How to get terminal width?

Quinn Dunkan quinn at bolivar.ugcs.caltech.edu
Thu May 4 01:03:04 EDT 2000


On 4 May 2000 00:32:57 GMT, Donn Cave <donn at u.washington.edu> wrote:
>Quoth kc5tja at garnet.armored.net (Samuel A. Falvo II):
>| In article <8457258D741DD411BD3D0050DA62365907A13D at huina.oceanic.com>, Doug
>| Stanfield wrote:
>| >COLUMNS is there on my just installed Mandrake 7, a new Storm install, a Red
>| >Hat 5.2, 6.1, and a Mandrake 6.x.  In my world thats almost universal,
>| >although the sometimes accessed Solaris system doesn't have it.
>|
>| With the example you gave above, it's anything *but* universal.  Both Storm
>| and Mandrake are RedHat derivatives.
>|
>| However, I would like to point out that my Debian Potato installation has
>| COLUMNS defined.  It would be more useful if it also had a ROWS variable set
>| up as well.  :)
>
>That's hysterical.  The Linux I have at hand is none of the above, and
>I don't have COLUMNS.  I don't know who normally sets this up, though,
>and for all I know it could be because I connected via ssh and not
>telnet or rlogin.  That reminds me of another point about COLUMNS -
>if you resize your window does COLUMNS change?  That's a question I
>I can't check, having access to no system that supports it, but it seems
>pretty unlikely.

Yes, it does (change).  $COLUMNS and $LINES is a shell thing, of course, so it
doesn't have much to do with your OS.  And yes, they *do* change when you
resize a window, that's what SIGWINCH does.  Well, ideally that's what
happens.  I've noticed some misbehaviour on some Irix systems but haven't
bothered to hunt it down.  It could be the SIGWINCH gets lost somewhere, at
which point an 'eval $(resize)' is in order...

I'm using zsh and I always have COLUMNS and LINES.  What shell are you using?

>| The question I'd like to know is, is this a POSIX requirement at all?  That
>| might prove to be useful research for when targetting applications that
>| require knowledge of terminal width.

Well, SIGWINCH isn't posix.1  Since the envvars are shell related, you'd
have to see if posix insists /bin/sh maintain them.


I've used getenv("COLUMNS"), falling back on the ioctl() under C.



More information about the Python-list mailing list