Fixes terminal size not being set properly

See at http://pexpect.sourceforge.net/pexpect.html the documentation
of interact. I include here for easy reference

  | Note that if you change the window size of the parent the SIGWINCH
  | signal will not be passed through to the child.
This commit is contained in:
Yannis Spiliopoulos
2017-01-23 13:28:04 -05:00
parent a87660e877
commit 09ec68d231
+24 -1
View File
@@ -3,6 +3,8 @@ import json
import os
import sys
import distutils.spawn
import shutil
import signal
import click
import crayons
@@ -420,11 +422,32 @@ def shell():
shell = os.environ['SHELL']
click.echo(crayons.yellow('Spawning environment shell ({0}).'.format(crayons.red(shell))))
c = pexpect.spawn("{0} -c '. {1}; exec {0} -i'".format(shell, activate_virtualenv(source=False)))
# Grab current terminal dimensions to replace the hardcoded default
# dimensions of pexpect
terminal_dimensions = shutil.get_terminal_size()
c = pexpect.spawn(
"{0} -c '. {1}; exec {0} -i'".format(
shell,
activate_virtualenv(source=False)
),
dimensions=(
terminal_dimensions.lines,
terminal_dimensions.columns
)
)
# Skip this step for bash.
if 'bash' not in shell:
c.send(activate_virtualenv() + '\n')
# Handler for terminal resizing events
# Must be defined here to have the shell process in its context, since we
# can't pass it as an argument
def sigwinch_passthrough(sig, data):
terminal_dimensions = shutil.get_terminal_size()
c.setwinsize(terminal_dimensions.lines, terminal_dimensions.columns)
signal.signal(signal.SIGWINCH, sigwinch_passthrough)
# Interact with the new shell.
c.interact()