getting *term window dimensions w/o curses

Erno Kuusela erno-news at erno.iki.fi
Sat Aug 4 18:05:15 EDT 2001


In article <slrn9mopj4.26a.sill at sill.silmarill.org>,
sill at optonline.net (Andrei Kulakov) writes:

| Is there some way to get aterm (and other terms) window dimension(s)
| without curses?

use google :)

--> 

>  From: Michael Hudson (mwh21 at cam.ac.uk)
>  Subject: Re: Console column Width 
>  Newsgroups: comp.lang.python
>  Date: 2001-03-14 00:48:06 PST 
> 
> 
> "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.



  -- erno



More information about the Python-list mailing list