Table

cli2 also offers a simple table rendering data that will do it’s best to word wrap cell data so that it fits in the terminal.

This Table module behaves like a list, and is pretty simple. Its purpose is to tabulate data and it’s going to brute force output sizes until it finds a match.

As such, it’s not a good module to display really a lot of data because it sacrifies performance for human readability.

cli2.Table.factory(['foo', 'bar'], ['much longer', 'test']).print()
foo          bar
much longer  test

Note

This would look better with color

cli2.Table.factory(dict(foo=1, bar=2), dict(foo=3, bar=4)).print()

Renders:

foo  bar
===  ===
1    2
3    4
class cli2.table.Column[source]

Column object

class cli2.table.Table(*args)[source]

Table object

calculate_columns(termsize)[source]

Calculate columns size based on termsize.

classmethod factory(*items)[source]

Instanciate a table with a bunch of items.

Params items:

Iterable of lists or dicts or tuples

print(print_function=None, termsize=None)[source]

Print the table.