[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: terminal
On December 1, 2002 07:03 am, Hugo Villeneuve wrote:
> On Sat, Nov 30, 2002 at 11:45:27AM -0800, Ben Bunker wrote:
> > Hello,
> >
> > Bit of a programming question here. I'm attempting to
> > write a scaled-down version of the more utility, and
> > I'm at a loss as to how to find the size of the
> > terminal (i.e., width, number of lines). Does anyone
> > have any insight into this? Thanks.
>
> There's a TIOCGWINSZ ioctl to get the window size (man 4 tty).
Assuming the user has set it right. ;-)
The low level method of this is to send a terminal capabilities inquiry
code to some terminals or terminal software. But inquiry code
emulation in the more marginal terminal emulations is hit or miss.
And the parsing logic can get ugly. Or....
The portable way of doing it (given that everything except ancient crusty
wyse magic cookie terminals accepts ANSI/VT codes) sounds ugly but
works nicely: The technique is to gradually send incrementing screen
positions {printf("\x1B[%d;%dH]",x,y);} and use the return character pos
inquiry code {printf("\x1B[6n");} and parse out the returned "\x1B[%d;%dH"
sequences until it's obvious you've hit the end of the screen because
they stop incrementing.
This method works even with very broken terminal emulation sw and should
be as close to universally applicable as I've found.
cheers
--dr
P.S. Join the campaign to remove terminfo and termcap from POSIX today!!!
s/term{info,cap}/ansi/ :-)
P.P.S. Less is often more better. :-) :-) :-)
--
dr@kyx.net pgp: http://dragos.com/kyxpgp
CanSecWest/core03 speakers on-line at http://cansecwest.com
- References:
- Re: terminal
- From: Hugo Villeneuve <harpagon@jwales.EINTR.net>