Skip to content

Commit

Permalink
Merge pull request #11 from detly/master
Browse files Browse the repository at this point in the history
Added screen size parameters.
  • Loading branch information
takluyver committed Mar 17, 2015
2 parents 91d734e + b1e6193 commit 3942883
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ptyprocess/ptyprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,20 @@ def __init__(self, pid, fd):
self.delayafterterminate = 0.1

@classmethod
def spawn(cls, argv, cwd=None, env=None, echo=True, preexec_fn=None):
def spawn(
cls, argv, cwd=None, env=None, echo=True, preexec_fn=None,
dimensions=(24, 80)):
'''Start the given command in a child process in a pseudo terminal.
This does all the fork/exec type of stuff for a pty, and returns an
instance of PtyProcess.
If preexec_fn is supplied, it will be called with no arguments in the
child process before exec-ing the specified command.
It may, for instance, set signal handlers to SIG_DFL or SIG_IGN.
Dimensions of the psuedoterminal used for the subprocess can be
specified as a tuple (rows, cols), or the default (24, 80) will be used.
'''
# Note that it is difficult for this method to fail.
# You cannot detect if the child process cannot start.
Expand Down Expand Up @@ -224,9 +229,9 @@ def spawn(cls, argv, cwd=None, env=None, echo=True, preexec_fn=None):
# allowing IOError for either.

if pid == CHILD:
# set default window size of 24 rows by 80 columns
# set window size
try:
_setwinsize(STDIN_FILENO, 24, 80)
_setwinsize(STDIN_FILENO, *dimensions)
except IOError as err:
if err.args[0] not in (errno.EINVAL, errno.ENOTTY):
raise
Expand Down Expand Up @@ -318,7 +323,7 @@ def spawn(cls, argv, cwd=None, env=None, echo=True, preexec_fn=None):
raise exception

try:
inst.setwinsize(24, 80)
inst.setwinsize(*dimensions)
except IOError as err:
if err.args[0] not in (errno.EINVAL, errno.ENOTTY):
raise
Expand Down Expand Up @@ -818,4 +823,4 @@ def write(self, s):
Returns the number of bytes written.
"""
b = s.encode(self.encoding)
return super(PtyProcessUnicode, self).write(b)
return super(PtyProcessUnicode, self).write(b)

0 comments on commit 3942883

Please sign in to comment.