mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 12:30:08 -06:00
Support terminal width on windows. Resolves #199
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user