-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableMaker.py
More file actions
55 lines (50 loc) · 2.48 KB
/
TableMaker.py
File metadata and controls
55 lines (50 loc) · 2.48 KB
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
from colorama import Fore
class TableMaker:
def __init__(self, num_columns, max_for_each_column, color_for_heading="WHITE"):
self.num_columns = num_columns
self.max_for_each_column = max_for_each_column # has to be a list
self.color_for_heading = color_for_heading.upper() # BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE
self.heading_dict = {}
self.top_line_2 = []
self.bottom_line_2 = []
self.bottom_line_func_2 = []
self.all_headings = []
def heading(self, list_of_headings):
for i in range(self.num_columns):
heading = "heading" + f'{i}'
self.all_headings.append(heading)
self.heading_dict[f'{heading}'] = (f'{list_of_headings[i]}', len(f'{list_of_headings[i]}'),
self.max_for_each_column[i])
top_line = ("╔" + "═" * self.heading_dict[heading][2] + "══╗")
bottom_line = ("•" + "-" * self.heading_dict[heading][2] + "--•")
bottom_line_func = ("-" + "-" * self.heading_dict[heading][2] + "---")
self.top_line_2.append(top_line)
self.bottom_line_2.append(bottom_line)
self.bottom_line_func_2.append(bottom_line_func)
for k in range(len(self.top_line_2)):
print(self.top_line_2[k], end=" ")
print()
for j in range(len(self.heading_dict)):
print("║ " + getattr(Fore, self.color_for_heading) + self.heading_dict['heading' + f'{j}'][0] + (" " * (
self.heading_dict['heading' + f'{j}'][2] - self.heading_dict['heading' + f'{j}'][1] + 1)),
sep=" ", end=Fore.WHITE + "║ ")
print()
for k in range(len(self.top_line_2)):
print(Fore.WHITE + self.bottom_line_2[k], end=" ")
print()
def items(self, list_of_items):
item_dict = {}
all_items = []
for i in range(self.num_columns):
item = "item" + f'{i}'
all_items.append(item)
item_dict[f'{item}'] = (f'{list_of_items[i]}', len(f'{list_of_items[i]}'))
for j in range(len(item_dict)):
print("║ " + item_dict['item' + f'{j}'][0] + (" " * (
self.max_for_each_column[j] - item_dict["item" + f'{j}'][1] + 1)), sep=" ",
end="║ ")
print()
def bottomline(self):
for k in range(len(self.top_line_2)):
print(self.bottom_line_func_2[k], end=" ")
print()