-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.py
88 lines (65 loc) · 2.03 KB
/
table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
__author__ = 'mattias'
from sys import stdout
global label_length
global label_style
def new_columns(columns, style):
if style == 1:
label_style = '='
elif style == 2:
label_style = '~'
elif style == 3:
label_style = '-'
elif style == 4:
label_style = '#'
elif style == 5:
label_style = '▬'
elif style == 6:
label_style = '▫'
else:
label_style = '='
for i in columns:
length = len(i)
stdout.write('+' + label_style * (length + 2) + '+')
print('\r')
for i in columns:
line_pos_right = ' |'
stdout.write('| ' + i + line_pos_right)
print('\r')
for i in columns:
stdout.write('+' + label_style * (length + 2) + '+')
print('\r')
# Add a row - this method adds a row to the table
def add_row(input):
for x in input:
input_length = len(x)
stdout.write('| ' + x + ' |')
print('\r')
for x in input:
length = len(x)
stdout.write('+' + '-' * (length + 2) + '+')
print('\r')
def add_column(column_title, column_data):
# This is for the column TITLE - eg. Title could be Animal Names
for m in column_title:
length = len(m)
stdout.write('+' + '=' * (length + 2) + '+')
print('\r')
for m in column_title:
line_pos_right = ' |'
stdout.write('| ' + m + ' |')
print('\r')
for m in column_title:
stdout.write('+' + '=' * (length + 2) + '+')
print('\r')
# ----------------------------------------------------
# This is for the DATA of the column - eg. Label == Animal Names, the Data would be Sparkles, Hunter, etc.
for m in column_data:
this_length = len(m)
if this_length < length:
wanted_l = length - this_length
elif this_length > length:
wanted_l = this_length - length
stdout.write('| ' + m + ' ' * (wanted_l) + ' |')
print('\r')
stdout.write('+' + '-' * (length + 2) + '+')
add_column(['Animal '], ['Tiger', 'Dolphin'])