def resize(self, rows, cols, em_dimensions=None, ctrl_l=True):
"""
Resizes the child process's terminal window to *rows* and *cols* by
first sending it a TIOCSWINSZ event and then sending ctrl-l.
If *em_dimensions* are provided they will be updated along with the
rows and cols.
The sending of ctrl-l can be disabled by setting *ctrl_l* to False.
"""
logging.debug(
"Resizing term %s to rows: %s, cols: %s, em_dimensions=%s"
% (self.term_id, rows, cols, em_dimensions))
if rows < 2:
rows = 24
if cols < 2:
cols = 80
self.rows = rows
self.cols = cols
self.term.resize(rows, cols, em_dimensions)
# Sometimes the resize doesn't actually apply (for whatever reason)
# so to get around this we have to send a different value than the
# actual value we want then send our actual value. It's a bug outside
# of Gate One that I have no idea how to isolate but this has proven to
# be an effective workaround.
import fcntl, termios
s = struct.pack("HHHH", rows, cols, 0, 0)
try:
fcntl.ioctl(self.fd, termios.TIOCSWINSZ, s)
except IOError:
# Process already ended--no big deal
return
try:
os.kill(self.pid, signal.SIGWINCH) # Send the resize signal
except OSError:
return # Process is dead. Can happen when things go quickly
if ctrl_l:
self.write(u'\x0c') # ctrl-l
评论列表
文章目录