summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Heeris <jason.heeris@gmail.com>2015-03-16 22:59:22 +1100
committerJason Heeris <jason.heeris@gmail.com>2015-03-16 22:59:22 +1100
commitd69bf09cb3833ec1d3381d38e3f005f7d3570428 (patch)
treeba4d493ac27a5eea718bd05faea7443e70d309dd
parent450f390eaecf88ad95f429ce8b5d03fc8381f158 (diff)
downloadpexpect-d69bf09cb3833ec1d3381d38e3f005f7d3570428.tar.gz
Allow specifying screen size for the subprocess in pexpect.spawn().
-rw-r--r--pexpect/pty_spawn.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/pexpect/pty_spawn.py b/pexpect/pty_spawn.py
index 0663926..23c6470 100644
--- a/pexpect/pty_spawn.py
+++ b/pexpect/pty_spawn.py
@@ -37,7 +37,8 @@ class spawn(SpawnBase):
def __init__(self, command, args=[], timeout=30, maxread=2000,
searchwindowsize=None, logfile=None, cwd=None, env=None,
- ignore_sighup=True, echo=True, preexec_fn=None):
+ ignore_sighup=True, echo=True, preexec_fn=None,
+ dimensions=None):
'''This is the constructor. The command parameter may be a string that
includes a command and any arguments to the command. For example::
@@ -170,6 +171,10 @@ class spawn(SpawnBase):
If preexec_fn is given, it will be called in the child process before
launching the given command. This is useful to e.g. reset inherited
signal handlers.
+
+ The dimensions attribute specifies the size of the pseudo-terminal as
+ seen by the subprocess, and is specified as a two-entry tuple (rows,
+ columns). If this is unspecified, the defaults in ptyprocess will apply.
'''
super(spawn, self).__init__(timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize,
logfile=logfile)
@@ -186,7 +191,7 @@ class spawn(SpawnBase):
self.args = None
self.name = '<pexpect factory incomplete>'
else:
- self._spawn(command, args, preexec_fn)
+ self._spawn(command, args, preexec_fn, dimensions)
def __str__(self):
'''This returns a human-readable string that represents the state of
@@ -222,7 +227,7 @@ class spawn(SpawnBase):
s.append('delayafterterminate: ' + str(self.delayafterterminate))
return '\n'.join(s)
- def _spawn(self, command, args=[], preexec_fn=None):
+ def _spawn(self, command, args=[], preexec_fn=None, dimensions=None):
'''This starts the given command in a child process. This does all the
fork/exec type of stuff for a pty. This is called by __init__. If args
is empty then command will be parsed (split on spaces) and args will be
@@ -277,6 +282,9 @@ class spawn(SpawnBase):
preexec_fn()
kwargs['preexec_fn'] = preexec_wrapper
+ if dimensions is not None:
+ kwargs['dimensions'] = dimensions
+
self.ptyproc = self.ptyprocess_class.spawn(self.args, env=self.env,
cwd=self.cwd, **kwargs)