3
def get_terminal_width():
5
import termios,fcntl,struct
6
call = fcntl.ioctl(0,termios.TIOCGWINSZ,"\000"*8)
7
height,width = struct.unpack( "hhhh", call ) [:2]
9
except (SystemExit, KeyboardInterrupt), e:
13
terminal_width = int(os.environ.get('COLUMNS', 80))-1
16
terminal_width = get_terminal_width()
18
def ansi_print(text, esc, file=None, newline=True, flush=False):
22
if esc and sys.platform != "win32" and file.isatty():
23
if not isinstance(esc, tuple):
25
text = (''.join(['\x1b[%sm' % cod for cod in esc]) +
27
'\x1b[0m') # ANSI color code "reset"