Console column Width

Nathan Heagy gervaserules at yahoo.com
Thu Mar 15 01:06:59 CET 2001


Yes, this does work, except on MacOSX, which appears to not have TIOCGWINSZ
in its TERMIOS module. Is this true for FreeBSD/other BSDs?

nathan


"Michael Hudson" <mwh21 at cam.ac.uk> wrote in message
news:m3snkg7n54.fsf at atrus.jesus.cam.ac.uk...
> "Nathan Heagy" <gervaserules at yahoo.com> writes:
>
> > I can't figure out how to learn the (linux) console's column width from
> > within a script? That is, without using curses.
>
> This works for me:
>
> def getwidth():
>     return getheightwidth()[1]
>
> # Eep!  this next should be made rather more portable (ie. fallback to
> # env vars, then tigetstr("lines"), etc).
> def getheightwidth():
>     height, width = struct.unpack(
>         "hhhh", ioctl(0, TERMIOS.TIOCGWINSZ ,"\000"*8))[0:2]
>     return height, width
>
> Cheers,
> M.
>
> --
>   Not only does the English Language borrow words from other
>   languages, it sometimes chases them down dark alleys, hits
>   them over the head, and goes through their pockets.   -- Eddy Peters





More information about the Python-list mailing list