How to get terminal width?

Jeff Bauer jbauer at rubic.com
Thu May 4 22:40:38 EDT 2000


Donn Cave wrote:
> Quoth newsbunny at noether.freeserve.co.uk (Martin P Holland):
> | stty size
> |
> | just gives the rows and columns here (linux) but may be this is
> | not standard.
> 
> It looks pretty good to me!  Ultrix 4.2, Digital UNIX 4.0, AIX 4.2,
> HP/UX 10.20, FreeBSD 4.0, 2 versions of Linux and BeOS 4.5 pass on
> this one, and that's all I can dig up to try, so it looks to me like
> the best bet so far.  Easiest to handle in Python, too.

Donn/Martin:

It fails on Solaris 2.6  (and probably other versions of Solaris):

$ stty size
unknown mode: size

$ stty
ispeed 88840 baud; ospeed 88824 baud; -parity cstopb hupcl loblk 
rows = 24; columns = 80; ypixels = 274; xpixels = 490;
quit = <undef>; erase = ^h; swtch = <undef>; 
-inpck -istrip icrnl -ixany ixoff onlcr 
echo echoe echok echoctl echoke iexten 

However, it might be worth coding a special stty.py module 
to hide platform differences, similar to what Marc-Andre 
Lemburg has done with platform.py.

Jeff Bauer
Rubicon Research




More information about the Python-list mailing list