[prev in list] [next in list] [prev in thread] [next in thread]
List: python-dev
Subject: Re: [Python-Dev] Fixing pty.spawn()
From: Gustavo Barbieri <barbieri () gmail ! com>
Date: 2005-09-27 19:47:45
Message-ID: 9ef20ef305092712473f961015 () mail ! gmail ! com
[Download RAW message or body]
The attached patch calls ioctl() to set master_fd win size.
I use fcntl and struct modules, I have hardcoded values from termios
since this module is deleted.
Is it ok?
--
Gustavo Sverzut Barbieri
---------------------------------------
Computer Engineer 2001 - UNICAMP
GPSL - Grupo Pro Software Livre
Cell..: +55 (19) 9165 8010
Jabber: gsbarbieri@jabber.org
ICQ#: 17249123
MSN: barbieri@gmail.com
Skype: gsbarbieri
GPG: 0xB640E1A2 @ wwwkeys.pgp.net
["pty_spawn_set_winsize.patch" (application/octet-stream)]
--- /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
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-dev%40progressive-comp.com
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic