@ -416,7 +416,7 @@ if hasattr(shutil, 'get_terminal_size'): # Python >= 3.3
else :
else :
_terminal_size = collections . namedtuple ( ' terminal_size ' , [ ' columns ' , ' lines ' ] )
_terminal_size = collections . namedtuple ( ' terminal_size ' , [ ' columns ' , ' lines ' ] )
def compat_get_terminal_size ( ) :
def compat_get_terminal_size ( fallback = ( 80 , 24 ) ) :
columns = compat_getenv ( ' COLUMNS ' , None )
columns = compat_getenv ( ' COLUMNS ' , None )
if columns :
if columns :
columns = int ( columns )
columns = int ( columns )
@ -428,14 +428,20 @@ else:
else :
else :
lines = None
lines = None
if columns < = 0 or lines < = 0 :
try :
try :
sp = subprocess . Popen (
sp = subprocess . Popen (
[ ' stty ' , ' size ' ] ,
[ ' stty ' , ' size ' ] ,
stdout = subprocess . PIPE , stderr = subprocess . PIPE )
stdout = subprocess . PIPE , stderr = subprocess . PIPE )
out , err = sp . communicate ( )
out , err = sp . communicate ( )
lines , column s = map ( int , out . split ( ) )
_columns , _line s = map ( int , out . split ( ) )
except Exception :
except Exception :
pass
_columns , _lines = _terminal_size ( * fallback )
if columns < = 0 :
columns = _columns
if lines < = 0 :
lines = _lines
return _terminal_size ( columns , lines )
return _terminal_size ( columns , lines )
try :
try :