summaryrefslogtreecommitdiff
path: root/pexpect/tests/sigwinch_report.py
blob: c7caf23b05a65c372fd757a5183c018229071db5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import signal, time, struct, fcntl, termios, os, sys

def getwinsize():
    """This returns the window size of the child tty.
    The return value is a tuple of (rows, cols).
    """
    if 'TIOCGWINSZ' in dir(termios):
        TIOCGWINSZ = termios.TIOCGWINSZ
    else:
        TIOCGWINSZ = 1074295912L # Assume
    s = struct.pack('HHHH', 0, 0, 0, 0)
    x = fcntl.ioctl(sys.stdout.fileno(), TIOCGWINSZ, s)
    return struct.unpack('HHHH', x)[0:2]

def handler(signum, frame):
    print 'signal'
    sys.stdout.flush()
    print 'SIGWINCH:', getwinsize ()
    sys.stdout.flush()

print "setting handler for SIGWINCH"
signal.signal(signal.SIGWINCH, handler)

while 1:
    sys.stdout.flush()
    time.sleep(1)