> The code for handling window resizing isn't jumping out at 
> me but I'll keep looking.

(...jumping out, rather unexpectedly!)

You might be interested in an ongoing discussion that I and Grant Edwards are 
holding in this newsgroup on the subject "Best way of finding terminal 
width/height?".

Thread summary:

There's a function that Chuck Blake wrote for detecting the current terminal 
size, available here:

http://pdos.csail.mit.edu/~cblake/cls/cls.py

You'll only need the first two functions for this task (ioctl_GWINSZ and 
terminal_size).

To monitor changes in window size, have a look at the signal module (in 
standard library). You can attach a monitor function to the signal 
signal.SIGWINCH, like so:

signal.signal(signal.SIGWINCH, report_terminal_size_change)

or, in context:

-------------------------------------------------------------------
#!/usr/bin/python
from cls import terminal_size

current_terminal_size = terminal_size()

_bTerminalSizeChanged = False

def report_terminal_size_change(signum, frame):
    global _bTerminalSizeChanged
    _bTerminalSizeChanged = True

def update_terminal_size():
    global _bTerminalSizeChanged, current_terminal_size
    current_terminal_size = terminal_size()
    _bTerminalSizeChanged = False

signal.signal(signal.SIGWINCH, report_terminal_size_change) 

while True:
    if _bTerminalSizeChanged:
        update_terminal_size()
        print current_terminal_size
----------------------------------------------------------------------

Take care!
/Joel
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to