getting terminal display size?

Grant Edwards grante at visi.com
Sun Feb 25 21:06:04 EST 2007


On 2007-02-26, jeff <jeffrey.aylesworth at gmail.com> wrote:

> I looked around a lot on the internet and couldn't find out how to do
> this, how do I get the sizer (in rows and columns) of the view?

You use the TIOCGWINSZ ioctl() call on the tty device in question.

  import termios, fcntl, struct, sys

  s = struct.pack("HHHH", 0, 0, 0, 0)
  fd_stdout = sys.stdout.fileno()
  x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
  print '(rows, cols, x pixels, y pixels) =',
  print struct.unpack("HHHH", x)



-- 
Grant Edwards
grante at visi.com



More information about the Python-list mailing list