def term_width():
""" Try and get the terminal width """
# Python 3.3 and newer
if getattr(os, 'get_terminal_size', None) is not None:
try:
return os.get_terminal_size().columns
except OSError:
pass
# No reliable/easy way on Windows in 3.2 and older
if sys.platform == 'win32':
return 80
try:
proc = subprocess.Popen(['tput cols'], shell=True, stdout=subprocess.PIPE)
out = proc.communicate()
if proc.wait() != 0:
raise OSError
return int(out[0])
except OSError:
return 80
评论列表
文章目录