Terminal width not available in Python 2

This commit is contained in:
nsubiron 2017-11-17 15:22:06 +01:00
parent 2c23fc1e0e
commit 54051420e6
1 changed files with 14 additions and 2 deletions

View File

@ -29,7 +29,6 @@ from __future__ import print_function
import argparse
import logging
import shutil
import sys
import time
@ -84,6 +83,18 @@ def convert_depth(depth):
color_depth = grayscale_colormap(gray_depth, 'jet') * 255
return color_depth
if sys.version_info >= (3, 3):
import shutil
def get_terminal_width():
return shutil.get_terminal_size((80, 20)).columns
else:
def get_terminal_width():
return 120
class App(object):
def __init__(
@ -184,7 +195,8 @@ class App(object):
speed=pack.forward_speed,
other_lane=100 * pack.intersection_otherlane,
offroad=100 * pack.intersection_offroad)
empty_space = shutil.get_terminal_size((80, 20)).columns - len(message)
empty_space = max(0, get_terminal_width() - len(message))
sys.stdout.write('\r' + message + empty_space * ' ')
sys.stdout.flush()