Skip to content

Commit 4f6e4ae

Browse files
committed
Support terminal width on windows. Resolves pre-commit#199
1 parent 1397445 commit 4f6e4ae

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

pre_commit/output.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
from __future__ import unicode_literals
22

3-
import os
4-
import subprocess
53
import sys
64

5+
from backports.shutil_get_terminal_size import get_terminal_size
6+
77
from pre_commit import color
88
from pre_commit import five
99

10-
1110
# TODO: smell: import side-effects
12-
try:
13-
if not os.environ.get('TERM'): # pragma: no cover (dumb terminal)
14-
raise OSError('Cannot determine width without TERM')
15-
else: # pragma no cover (windows)
16-
COLS = int(
17-
subprocess.Popen(
18-
('tput', 'cols'), stdout=subprocess.PIPE,
19-
).communicate()[0] or
20-
# Default in the case of no terminal
21-
80
22-
)
23-
except OSError: # pragma: no cover (windows)
24-
COLS = 80
11+
# TODO: https://github.com/chrippa/backports.shutil_get_terminal_size/issues/4
12+
COLS = get_terminal_size().columns or 80
2513

2614

2715
def get_hook_message(

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
install_requires=[
4242
'argparse',
4343
'aspy.yaml',
44+
'backports.shutil_get_terminal_size',
4445
'cached-property',
4546
'jsonschema',
4647
'nodeenv>=0.11.1',

0 commit comments

Comments
 (0)