diff --git a/compose/cli/formatter.py b/compose/cli/formatter.py index 13794b89a..c1f43ed7a 100644 --- a/compose/cli/formatter.py +++ b/compose/cli/formatter.py @@ -2,20 +2,25 @@ from __future__ import absolute_import from __future__ import unicode_literals import logging -import os +import shutil import six import texttable from compose.cli import colors +if hasattr(shutil, "get_terminal_size"): + from shutil import get_terminal_size +else: + from backports.shutil_get_terminal_size import get_terminal_size + def get_tty_width(): - tty_size = os.popen('stty size 2> /dev/null', 'r').read().split() - if len(tty_size) != 2: + try: + width, _ = get_terminal_size() + return int(width) + except OSError: return 0 - _, width = tty_size - return int(width) class Formatter: diff --git a/requirements.txt b/requirements.txt index ed1c87693..f2e66b34d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +backports.shutil_get_terminal_size==1.0.0 backports.ssl-match-hostname==3.5.0.1; python_version < '3' cached-property==1.3.0 certifi==2017.4.17 diff --git a/setup.py b/setup.py index c3e214c22..23ae08a12 100644 --- a/setup.py +++ b/setup.py @@ -55,7 +55,8 @@ extras_require = { ':python_version < "3.2"': ['subprocess32 >= 3.5.4, < 4'], ':python_version < "3.4"': ['enum34 >= 1.0.4, < 2'], ':python_version < "3.5"': ['backports.ssl_match_hostname >= 3.5, < 4'], - ':python_version < "3.3"': ['ipaddress >= 1.0.16, < 2'], + ':python_version < "3.3"': ['backports.shutil_get_terminal_size == 1.0.0', + 'ipaddress >= 1.0.16, < 2'], ':sys_platform == "win32"': ['colorama >= 0.4, < 1'], 'socks': ['PySocks >= 1.5.6, != 1.5.7, < 2'], }