| Store | Cart

detect terminal width

From: Michael Hudson <mwh...@cam.ac.uk>
02 May 2001 14:57:53 +0100
"Bruce Edge" <bedge at troikanetworks.com> writes:

> Without using curses, can I detect terminal row/col settings from python?

Hmm, I posted this just a few weeks back:

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


  I'll write on my monitor fifty times 'I must not post self-indulgent
  wibble nobody is interested in to ucam.chat just because I'm bored
  and I can't find the bug I'm supposed to fix'.
                                            -- Steve Kitson, ucam.chat

Recent Messages in this Thread
Bruce Edge May 02, 2001 01:41 pm
Michael Hudson May 02, 2001 01:57 pm
Bruce Edge May 02, 2001 02:43 pm
Messages in this thread

Previous post: doctest or pyunit?
Next post: CGI Redirect