Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
Adding examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robpol86 committed Sep 11, 2014
1 parent c3b80b0 commit cecff0e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
31 changes: 31 additions & 0 deletions example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
"""Simple example usage of terminaltables without any other dependencies.
Just prints sample text and exits.
"""

from __future__ import print_function
from terminaltables import AsciiTable, UnixTable


table_data = [
['Platform', 'Years', 'Notes'],
['Mk5', '2007-2009', 'The Golf Mk5 Variant was\nintroduced in January 2007 and\nproduced up to March 2009.'],
['MKVI', '2009-2013', 'Might actually be Mk5.'],
]
table = AsciiTable(table_data, 'Jetta SportWagen')
print()
print(table.table)

table = UnixTable(table_data, 'Jetta SportWagen')
table.inner_row_border = True
table.justify_columns[2] = 'right'
print()
print(table.table)

table.outer_border = False
table.justify_columns[1] = 'center'
print()
print(table.table)

print()
49 changes: 49 additions & 0 deletions example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python
"""Example usage of terminaltables using colorclass.
Just prints sample text and exits.
"""

from __future__ import print_function
from colorclass import Color
from terminaltables import UnixTable


table_data = [
[Color('{autogreen}<10ms{/autogreen}'), '192.168.0.100, 192.168.0.101'],
[Color('{autoyellow}10ms <= 100ms{/autoyellow}'), '192.168.0.102, 192.168.0.103'],
[Color('{autored}>100ms{/autored}'), '192.168.0.105'],
]
table = UnixTable(table_data)
table.inner_heading_row_border = False
print()
print(table.table)

table.title = '192.168.0.105'
table.justify_columns = {0: 'center', 1: 'center', 2: 'center'}
table.inner_row_border = True
table.table_data = [
[Color('Low Space'), Color('{autocyan}Nominal Space{/autocyan}'), Color('Excessive Space')],
[Color('Low Load'), Color('Nominal Load'), Color('{autored}High Load{/autored}')],
[Color('{autocyan}Low Free RAM{/autocyan}'), Color('Nominal Free RAM'), Color('High Free RAM')],
]
print()
print(table.table)

table.title = None
table.outer_border = False
table.table_data = [['A', 'B'], ['C', 'D']]
print()
print(table.table)

table.outer_border = True
table.inner_row_border = False
table.inner_column_border = False
print()
print(table.table)

table = UnixTable([['Obey Obey Obey Obey']], 'Instructions')
print()
print(table.table)

print()

0 comments on commit cecff0e

Please sign in to comment.