OLD | NEW |
(Empty) | |
| 1 ''' |
| 2 PEXPECT LICENSE |
| 3 |
| 4 This license is approved by the OSI and FSF as GPL-compatible. |
| 5 http://opensource.org/licenses/isc-license.txt |
| 6 |
| 7 Copyright (c) 2012, Noah Spurrier <noah@noah.org> |
| 8 PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY |
| 9 PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE |
| 10 COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. |
| 11 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 12 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 13 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 14 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 18 |
| 19 ''' |
| 20 from __future__ import print_function |
| 21 |
| 22 import signal, time, struct, fcntl, termios, sys |
| 23 |
| 24 def getwinsize(): |
| 25 '''This returns the window size of the child tty. |
| 26 The return value is a tuple of (rows, cols). |
| 27 ''' |
| 28 if 'TIOCGWINSZ' in dir(termios): |
| 29 TIOCGWINSZ = termios.TIOCGWINSZ |
| 30 else: |
| 31 TIOCGWINSZ = 1074295912 # Assume |
| 32 s = struct.pack('HHHH', 0, 0, 0, 0) |
| 33 x = fcntl.ioctl(sys.stdout.fileno(), TIOCGWINSZ, s) |
| 34 return struct.unpack('HHHH', x)[0:2] |
| 35 |
| 36 def handler(signum, frame): |
| 37 print('signal') |
| 38 sys.stdout.flush() |
| 39 print('SIGWINCH:', getwinsize ()) |
| 40 sys.stdout.flush() |
| 41 |
| 42 print("Initial Size:", getwinsize()) |
| 43 print("setting handler for SIGWINCH") |
| 44 signal.signal(signal.SIGWINCH, handler) |
| 45 print("READY") |
| 46 |
| 47 while 1: |
| 48 sys.stdout.flush() |
| 49 time.sleep(1) |
| 50 |
OLD | NEW |