File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 11from __future__ import unicode_literals
22
3+ import os
4+ import subprocess
35import sys
46
57from backports .shutil_get_terminal_size import get_terminal_size
68
79from pre_commit import color
810from pre_commit import five
911
10- # TODO: smell: import side-effects
11- # TODO: https://github.com/chrippa/backports.shutil_get_terminal_size/issues/4
12- COLS = get_terminal_size ().columns or 80
12+
13+ def _get_cols_from_tput (): # pragma: no cover (fallback)
14+ if not os .environ .get ('TERM' ):
15+ return 80
16+ else :
17+ return int (
18+ subprocess .Popen (
19+ ('tput' , 'cols' ), stdout = subprocess .PIPE ,
20+ ).communicate ()[0 ] or
21+ # Default in the case of no terminal
22+ 80
23+ )
24+
25+
26+ COLS = get_terminal_size ((0 , 0 )).columns or _get_cols_from_tput ()
1327
1428
1529def get_hook_message (
You can’t perform that action at this time.
0 commit comments