mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Support terminal width on windows. Resolves #199
This commit is contained in:
parent
139744582b
commit
4f6e4aedee
2 changed files with 5 additions and 16 deletions
|
|
@ -1,27 +1,15 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from backports.shutil_get_terminal_size import get_terminal_size
|
||||
|
||||
from pre_commit import color
|
||||
from pre_commit import five
|
||||
|
||||
|
||||
# TODO: smell: import side-effects
|
||||
try:
|
||||
if not os.environ.get('TERM'): # pragma: no cover (dumb terminal)
|
||||
raise OSError('Cannot determine width without TERM')
|
||||
else: # pragma no cover (windows)
|
||||
COLS = int(
|
||||
subprocess.Popen(
|
||||
('tput', 'cols'), stdout=subprocess.PIPE,
|
||||
).communicate()[0] or
|
||||
# Default in the case of no terminal
|
||||
80
|
||||
)
|
||||
except OSError: # pragma: no cover (windows)
|
||||
COLS = 80
|
||||
# TODO: https://github.com/chrippa/backports.shutil_get_terminal_size/issues/4
|
||||
COLS = get_terminal_size().columns or 80
|
||||
|
||||
|
||||
def get_hook_message(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue