[Pythonmac-SIG] resizing terminal and curses

Nicholas Cole nicholas.cole at gmail.com
Sun Mar 19 14:55:20 CET 2006


I'm still trying to investigate this problem with resizing terminals. 
I've found a method which can reliably determine the size of the
terminal on OS X (not completely tested), which is to do the
following:

struct.unpack('hh', fcntl.ioctl(sys.stdout.fileno(),
termios.TIOCGWINSZ, 'xxxx'))

However, there still seems to be a problem in the underlying curses
code.  The following python script will crash on OS X 10.4 in X11
(xterm) or terminal.app if the terminal is made larger than its
original size - curses refuses to believe it is possible to create a
window larger than the size of the terminal when curses was
initialised.

Terminal.app behaives particularly strangely - crashing when the
window is enlarged for the second time (xterm crashes immediately),
though not the first;  both terminals have problems displaying the
window as it is made smaller, even though they do not crash.

Best wishes,

N.

import curses
import os
import sys
import termios
import fcntl
import struct

def main(screen):
        while 1:
                y, x = struct.unpack('hh',
fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, 'xxxx'))
                win = curses.newwin(y-1, x-2, 0,0)
                #y, x = win.getmaxyx()

                win.addstr("Terminal Size = %s x %s" % (y, x))
                win.refresh()
                curses.napms(100)


if __name__ == '__main__':
        curses.wrapper(main)


More information about the Pythonmac-SIG mailing list