How to find out width of terminal
I wonder how CLI applications know the width of the terminal. For example, how does ls know how many columns to use?
How do package managers like pacman know what length to make the download progress bar? Also, how do they redraw the progress bar in the same line? |
Quote:
man 2 stty , etc. |
That didn't really help.
Also, I want to be able to do this from C, Perl, Python, etc. I was thinking more like ANSI escape codes, I know that there is a code to set the cursor position, isn't there some escape code that tells the terminal to report back it's size? |
Quote:
Code:
sergei@amdam2:~> stty -a |
Good, but can stty set the cursor position (not that it really matters, because I know how to do it using ANSI codes).
ANd is it possible to get this info without executing an external program? |
Quote:
|
Quote:
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ And there are ncurses wrappers in Perl, Python, and heck, probably every other language ever written. |
I am not talking about applications that make text "GUI"s.
I am talking about applications that draw progress bars in the sommand line, like most package managers do, or wget, for example. |
echo $COLUMNS
it's an environement variable also you can find out how many lines by echo $LINES |
But I am not just talking about Bash scripts, but for other scripting and compiled languages.
|
You can get/set environment variables from most languages. I think certain versions of Java disallow this, but most Linux hosted languages that I've used are environmentally friendly.
--- rod. |
Quote:
|
All times are GMT -5. The time now is 04:05 PM. |