@@ -92,8 +92,27 @@ def shorten_string(string, max_width):
92
92
return string
93
93
visible = max_width - 16 - int (log10 (string_len ))
94
94
# expected suffix len "...(and XXXXX more)"
95
- return '' .join ((string [:visible ], '...(and ' , str (string_len - visible ),
96
- ' more)' ))
95
+ return u'' .join ((string [:visible ], u'...(and ' , str (string_len - visible ),
96
+ u' more)' ))
97
+
98
+
99
+ def get_console_width ():
100
+ try :
101
+ cols = int (os .environ ['COLUMNS' ])
102
+ except (KeyError , ValueError ):
103
+ pass
104
+ else :
105
+ if cols >= 25 :
106
+ return cols
107
+
108
+ try :
109
+ cols = max (25 , int (os .popen ('stty size' , 'r' ).read ().split ()[1 ]))
110
+ except Exception :
111
+ pass
112
+ else :
113
+ return cols
114
+
115
+ return 100
97
116
98
117
99
118
def shprint (command , * args , ** kwargs ):
@@ -109,10 +128,7 @@ def shprint(command, *args, **kwargs):
109
128
filter_out = kwargs .pop ('_filterout' , None )
110
129
if len (logger .handlers ) > 1 :
111
130
logger .removeHandler (logger .handlers [1 ])
112
- try :
113
- columns = max (25 , int (os .popen ('stty size' , 'r' ).read ().split ()[1 ]))
114
- except :
115
- columns = 100
131
+ columns = get_console_width ()
116
132
command_path = str (command ).split ('/' )
117
133
command_string = command_path [- 1 ]
118
134
string = ' ' .join (['running' , command_string ] + list (args ))
0 commit comments