A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20050927/f3303dad/pty_spawn_set_winsize.obj below:

--- /usr/lib/python2.3/pty.py 2005-09-20 15:45:48.000000000 -0300 +++ /tmp/pty.py 2005-09-27 16:38:30.000000000 -0300 @@ -8,6 +8,8 @@ from select import select import os +import fcntl +import struct # Absurd: import termios and then delete it. This is to force an attempt # to import pty to raise an ImportError on platforms that lack termios. @@ -29,6 +31,9 @@ CHILD = 0 +TIOCGWINSZ = 21523 +TIOCSWINSZ = 21524 + def openpty(): """openpty() -> (master_fd, slave_fd) Open a pty master/slave pair, using os.openpty() if possible.""" @@ -157,6 +162,26 @@ data = stdin_read(STDIN_FILENO) _writen(master_fd, data) +def _getwinsize(fd): + """ + 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(fd, TIOCGWINSZ, s) + return struct.unpack('HHHH', x )[0:2] + +def _setwinsize(fd, 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. + """ + s = struct.pack('HHHH', r, c, 0, 0) + fcntl.ioctl(fd, TIOCSWINSZ, s) + def spawn(argv, master_read=_read, stdin_read=_read): """Create a spawned process.""" if type(argv) == type(''): @@ -167,6 +192,10 @@ try: mode = tty.tcgetattr(STDIN_FILENO) tty.setraw(STDIN_FILENO) + + r, c = _getwinsize(STDOUT_FILENO) + _setwinsize(master_fd, r, c) + restore = 1 except tty.error: # This is the same as termios.error restore = 0

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4