> does anybody know how i can get the COLUMNS value associated with the
> shell that a command-line program is running in?
answered my own question, via a half-hour of googling. man, how did
anybody *ever* program before the web? this code will do it:
winsize size;
int stat;
memset(&size, 0, sizeof(size));
stat = ioctl(STDOUT_FILENO, TIOCGWINSZ, &size);
if (stat == 0)
{
// make use of size.ws_col, size.ws_row, etc.
}
the ioctl() call will fail if your program isn't connected to a live
terminal, which can happen if it's run by being double-clicked in a
finder window for instance, so testing 'stat' before using the 'size'
struct is important. you'll have to include <sys/ioctl.h> and possibly
other headers.
Mike Hall - 26 Sep 2004 06:43 GMT
Jøhnny FävòrÃtê it means halo, then resonate" wrote:
>J¿hnny FÂvÂrÂt (it means "halo, then resonate") wrote:
>> does anybody know how i can get the COLUMNS value associated with the
>> shell that a command-line program is running in?
Yes, just 'export' it, so child processes can see it.
$ echo $COLUMNS
80
$ set | grep COL
COLUMNS=80
$ env | grep COL
$
The shell variable is 'set' for the current shell, but it's not in the exported
environment available to the children. 'export COLUMNS' (or whatever
for csh, tcsh), and the children will see it, and 'getenv' will be happy to
give you the value.
Or, if you really like 'ioctl's, that's the other way to go.
Can also use 'signal' to catch SIGWINCH signals.
Jøhnny Fävòrítê (it means "halo, then resonate") - 26 Sep 2004 10:07 GMT
> Yes, just 'export' it, so child processes can see it.
that would require everybody who uses the program to have a special bash
start-up script though, right? yucko. at least i know it's possible to
do it that way, though.
> Can also use 'signal' to catch SIGWINCH signals.
do those signals fire whenever the terminal size changes? that would be
handy.
Miro Jurisic - 26 Sep 2004 17:19 GMT
> > Can also use 'signal' to catch SIGWINCH signals.
>
> do those signals fire whenever the terminal size changes? that would be
> handy.
Yes.
meeroh

Signature
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>