[GRASS5] v.digit and xterm size

Glynn Clements glynn.clements at virgin.net
Wed Jul 31 14:37:54 EDT 2002


Markus Neteler wrote:

> to fix a (small) problem for v.digit which gets stalled
> when the terminal is smaller that 80x24, I want to add
> a related test. Something like 
> 
>  TERM_COLUMNS = getenv("COLUMNS");
>  TERM_ROWS    = getenv("ROWS");
> 
> Of course that's not working, $COLUMNS seems not to be
> generally present.
> 
> Is there a way to got COLUMNS and ROWS (sorry for the naive question)?

This is handled by the curses library:

       The  integer  variables  LINES  and  COLS  are  defined in
       <curses.h> and will be filled in by initscr with the  size
       of the screen.  The constants TRUE and FALSE have the val­
       ues 1 and 0, respectively.

Of course, as with all curses functionality, it requires that the
terminfo (or termcap) entry has the correct data.

> Maybe 'stty' (is that portable)?

gtty(), tcgetattr() and ioctl(TCGETA) are concerned with low-level
issues such as flow control, parity, echo etc.

The size can be usually be obtained using ioctl(TIOCGWINSZ) (although
this may not work for a real terminal which is connected to a serial
port, it should work for any "terminal" which is implemented by a
user-space program, e.g. xterm, sshd, in.telnetd etc).

Most modern versions of curses will do this automatically and,
assuming that it provides sensible values, override the values from
terminfo (or termcap).

Also, if the terminal size changes, the foreground process group will
receive SIGWINCH. This will typically result in the curses library
calling ioctl(TIOCGWINSZ) and updating LINES and COLS accordingly.

-- 
Glynn Clements <glynn.clements at virgin.net>



More information about the grass-dev mailing list