[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pythonmac-SIG] resizing terminal and curses

From: Nicholas Cole
Subject: Re: [Pythonmac-SIG] resizing terminal and curses
Date: Sun, 19 Mar 2006 13:55:20 +0000

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

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

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,


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))

if __name__ == '__main__':

reply via email to

[Prev in Thread] Current Thread [Next in Thread]