Skip to content

Commit

Permalink
Pass size of the external tty into the container
Browse files Browse the repository at this point in the history
Workaround the issue in Docker where the terminal has a strange size:
moby/moby#35407

This issue is purportedly fixed but I'm still seeing it.
  • Loading branch information
grahamlyons committed Apr 5, 2019
1 parent 128c029 commit 9719d3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cdflow.py
Expand Up @@ -201,6 +201,10 @@ def docker_run(
'mode': 'ro',
}
if _command(command) == 'shell':
columns = int(check_output(['tput', 'cols']))
lines = int(check_output(['tput', 'lines']))
environment_variables['COLUMNS'] = columns
environment_variables['LINES'] = lines
container = docker_client.containers.create(
image_id,
command=command,
Expand Down
12 changes: 10 additions & 2 deletions test/test_docker.py
@@ -1,6 +1,7 @@
import unittest
from hashlib import sha256
from string import printable
from copy import deepcopy

import docker
from docker.client import DockerClient
Expand Down Expand Up @@ -244,7 +245,10 @@ def test_run_shell_command(self, fixtures):
}
docker_client.containers.create.return_value = container

with patch('cdflow.dockerpty') as dockerpty:
with patch('cdflow.dockerpty') as dockerpty, patch(
'cdflow.check_output',
) as check_output:
check_output.return_value = '42\n'
exit_status, output = docker_run(
docker_client,
image_id,
Expand All @@ -260,10 +264,14 @@ def test_run_shell_command(self, fixtures):
assert exit_status == 0
assert output == 'Shell end'

expected_environment_variable = deepcopy(environment_variables)
expected_environment_variable['COLUMNS'] = 42
expected_environment_variable['LINES'] = 42

docker_client.containers.create.assert_called_once_with(
image_id,
command=command,
environment=environment_variables,
environment=expected_environment_variable,
volumes={
project_root: {
'bind': project_root,
Expand Down

0 comments on commit 9719d3b

Please sign in to comment.