Console column Width

Michael Hudson mwh21 at cam.ac.uk
Wed Mar 14 03:47:19 EST 2001


"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