2014-01-06 03:26:32 +01:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import absolute_import
|
2013-12-11 15:25:32 +01:00
|
|
|
import os
|
2014-01-09 16:32:06 +01:00
|
|
|
import texttable
|
2014-01-06 04:13:41 +01:00
|
|
|
|
2013-12-11 15:25:32 +01:00
|
|
|
|
2014-08-07 18:30:01 +02:00
|
|
|
def get_tty_width():
|
|
|
|
tty_size = os.popen('stty size', 'r').read().split()
|
|
|
|
if len(tty_size) != 2:
|
|
|
|
return 80
|
|
|
|
_, width = tty_size
|
2014-08-26 04:11:50 +02:00
|
|
|
return int(width)
|
2014-08-07 18:30:01 +02:00
|
|
|
|
|
|
|
|
2013-12-11 15:25:32 +01:00
|
|
|
class Formatter(object):
|
|
|
|
def table(self, headers, rows):
|
2014-08-07 18:30:01 +02:00
|
|
|
table = texttable.Texttable(max_width=get_tty_width())
|
2013-12-11 15:25:32 +01:00
|
|
|
table.set_cols_dtype(['t' for h in headers])
|
|
|
|
table.add_rows([headers] + rows)
|
|
|
|
table.set_deco(table.HEADER)
|
|
|
|
table.set_chars(['-', '|', '+', '-'])
|
|
|
|
|
|
|
|
return table.draw()
|