formatter.py 416 B

123456789101112131415
  1. import texttable
  2. import os
  3. class Formatter(object):
  4. def table(self, headers, rows):
  5. height, width = os.popen('stty size', 'r').read().split()
  6. table = texttable.Texttable(max_width=width)
  7. table.set_cols_dtype(['t' for h in headers])
  8. table.add_rows([headers] + rows)
  9. table.set_deco(table.HEADER)
  10. table.set_chars(['-', '|', '+', '-'])
  11. return table.draw()