Get terminal size in perl and python
Grant Edwards
grante at visi.com
Thu Mar 8 15:18:43 EST 2001
In article <mailman.984079092.10641.python-list at python.org>, Kalle Svensson wrote:
>Sez Egbert Bouwman:
>> My perl correspondent uses:
>> use Term::ReadKey;
>> ($cols,$lines)=GetTerminalSize()
>> What is the python equivalent ?
>
>I'd use os.environ["COLUMNS"] and os.environ["LINES"], but I've no idea
>about how portable they are.
In most Unixes you'd be better off using the ioctl() call (the
details of which I can't remember at the moment -- I thought it
was in the termios struct, but I can't find it). The
environment variables are frozen at the time your program is
invoked and won't reflect any window resizing done since then.
If you start with the os.environ values you should then catch
SIGWINCH signals that are sent when the window is resized.
--
Grant Edwards grante Yow! My LIBRARY CARD
at expired...
visi.com
More information about the Python-list
mailing list