diff options
author | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2003-05-08 00:35:44 +0000 |
---|---|---|
committer | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2003-05-08 00:35:44 +0000 |
commit | fe22fef9e0deca1a44295ea071e0f30e8650e825 (patch) | |
tree | e6ac5040ddcef8c0ea3769598fed764fd26aebec | |
parent | 2bfd0a230a8e02af456bfc65cac8a76fd1cb44cd (diff) | |
download | pexpect-fe22fef9e0deca1a44295ea071e0f30e8650e825.tar.gz |
Adding support to set/get child windows size.
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@193 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r-- | pexpect/cvs.conf | 1 | ||||
-rw-r--r-- | pexpect/pexpect.py | 101 | ||||
-rw-r--r-- | pexpect/tests/sigwinch_report.py | 2 |
3 files changed, 71 insertions, 33 deletions
diff --git a/pexpect/cvs.conf b/pexpect/cvs.conf index 27e618c..78d649a 100644 --- a/pexpect/cvs.conf +++ b/pexpect/cvs.conf @@ -5,5 +5,6 @@ export CVS_RSH=ssh export CVSROOT=:ext:noah@cvs.pexpect.sourceforge.net:/cvsroot/pexpect export PATH=$PATH:tools/ export PROJECT_PEXPECT_HOME=`pwd` +export PYTHONPATH=$PROJET_PEXPECT_HOME/$PYTHONPATH alias sf="ssh noah@use-pr-shell1.sourceforge.net" diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py index 2208e18..be671a2 100644 --- a/pexpect/pexpect.py +++ b/pexpect/pexpect.py @@ -192,8 +192,9 @@ class spawn: raise ExceptionPexpect('Pexpect: pty.fork() failed: ' + str(e)) if self.pid == 0: # Child - try: # Some platforms do not like _setwinsize (for example, Cygwin). - _setwinsize(24, 80) + try: # Some platforms do not like setwinsize (Cygwin). + self.child_fd = sys.stdout.fileno() + self.setwinsize(24, 80) except: pass # Do not allow child to inherit open file descriptors from parent. @@ -644,7 +645,8 @@ class spawn: raise def expect_list(self, pattern_list, timeout = -1): - """This takes a list of compiled regular expressions and returns + """ + This takes a list of compiled regular expressions and returns the index into the pattern_list that matched the child's output. This is called by expect(). It is similar to the expect() method except that expect_list() is not overloaded. You must not pass @@ -693,6 +695,41 @@ class spawn: self.match = None raise + def getwinsize(self): + """ + This returns the window size of the child tty. + The return value is a tuple of (rows, cols). + """ + + s = struct.pack('HHHH', 0, 0, 0, 0) + x = fcntl.ioctl(self.fileno(), termios.TIOCGWINSZ, s) + return struct.unpack('HHHH', x)[0:2] + + def setwinsize(self, r, c): + """ + This sets the windowsize of the child tty. + This will cause a SIGWINCH signal to be sent to the child. + This does not change the physical window size. + It changes the size reported to TTY-aware applications like + vi or curses -- applications that respond to the SIGWINCH signal. + """ + # Check for buggy platforms. Some Python versions on some platforms + # (notably OSF1 Alpha and RedHat 7.1) truncate the value for + # termios.TIOCSWINSZ. It is not clear why this happens. + # These platforms don't seem to handle the signed int very well; + # yet other platforms like OpenBSD have a large negative value for + # TIOCSWINSZ and they don't have a truncate problem. + # Newer versions of Linux have totally different values for TIOCSWINSZ. + # + # Note that this fix is a hack. + TIOCSWINSZ = termios.TIOCSWINSZ + if TIOCSWINSZ == 2148037735L: # L is not required in Python >= 2.2. + TIOCSWINSZ = -2146929561 # Same bits, but with sign. + + # Note, assume ws_xpixel and ws_ypixel are zero. + s = struct.pack('HHHH', r, c, 0, 0) + fcntl.ioctl(self.fileno(), TIOCSWINSZ, s) + def interact(self, escape_character = chr(29)): """This gives control of the child process to the interactive user (the human at the keyboard). @@ -764,35 +801,6 @@ def _which (filename): return f return None -def _setwinsize(r, c): - """This sets the windowsize of the tty for stdout. - This does not change the physical window size. - It changes the size reported to TTY-aware applications like - vi or curses -- applications that respond to the SIGWINCH signal. - This is used by __spawn to set the tty window size of the child. - """ - # Check for buggy platforms. Some Pythons on some platforms - # (notably OSF1 Alpha and RedHat 7.1) truncate the value for - # termios.TIOCSWINSZ. It is not clear why this happens. - # These platforms don't seem to handle the signed int very well; - # yet other platforms like OpenBSD have a large negative value for - # TIOCSWINSZ and they don't truncate. - # Newer versions of Linux have totally different values for TIOCSWINSZ. - # - # Note that this fix is a hack. - TIOCSWINSZ = termios.TIOCSWINSZ - if TIOCSWINSZ == 2148037735L: # L is not required in Python 2.2. - TIOCSWINSZ = -2146929561 # Same number in binary, but with sign. - - # Assume ws_xpixel and ws_ypixel are zero. - s = struct.pack("HHHH", r, c, 0, 0) - fcntl.ioctl(sys.stdout.fileno(), TIOCSWINSZ, s) - -def _getwinsize(): - s = struct.pack("HHHH", 0, 0, 0, 0) - x = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s) - return struct.unpack("HHHH", x) - def _split_command_line(command_line): """This splits a command line into a list of arguments. It splits arguments on spaces, but handles @@ -951,3 +959,32 @@ def _split_command_line(command_line): ## self.buffer = piece+self.buffer +#def _setwinsize(r, c): +# """This sets the windowsize of the tty for stdout. +# This does not change the physical window size. +# It changes the size reported to TTY-aware applications like +# vi or curses -- applications that respond to the SIGWINCH signal. +# This is used by __spawn to set the tty window size of the child. +# """ +# # Check for buggy platforms. Some Pythons on some platforms +# # (notably OSF1 Alpha and RedHat 7.1) truncate the value for +# # termios.TIOCSWINSZ. It is not clear why this happens. +# # These platforms don't seem to handle the signed int very well; +# # yet other platforms like OpenBSD have a large negative value for +# # TIOCSWINSZ and they don't truncate. +# # Newer versions of Linux have totally different values for TIOCSWINSZ. +# # +# # Note that this fix is a hack. +# TIOCSWINSZ = termios.TIOCSWINSZ +# if TIOCSWINSZ == 2148037735L: # L is not required in Python 2.2. +# TIOCSWINSZ = -2146929561 # Same number in binary, but with sign. +# +# # Assume ws_xpixel and ws_ypixel are zero. +# s = struct.pack("HHHH", r, c, 0, 0) +# fcntl.ioctl(sys.stdout.fileno(), TIOCSWINSZ, s) +# +#def _getwinsize(): +# s = struct.pack("HHHH", 0, 0, 0, 0) +# x = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s) +# return struct.unpack("HHHH", x) + diff --git a/pexpect/tests/sigwinch_report.py b/pexpect/tests/sigwinch_report.py index bb2f45b..f7090cc 100644 --- a/pexpect/tests/sigwinch_report.py +++ b/pexpect/tests/sigwinch_report.py @@ -4,7 +4,7 @@ import signal, os def getwinsize(): s = struct.pack('HHHH', 0, 0, 0, 0) x = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, s) - return struct.unpack('HHHH', x) + return struct.unpack('HHHH', x)[0:2] def handler(signum, frame): print 'SIGWINCH:', getwinsize () |