-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.py
84 lines (66 loc) · 2.47 KB
/
results.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
# !/usr/bin/env python3
from rich import box
from rich.align import Align
from rich.console import Console, Group
from rich.columns import Columns
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
# Make the console object
c = Console()
class Results:
def set_output_type(self) -> str:
output_type: str = c.input(f'''[bright_white]
Enter output format (`p` = Panels or `t` = Table) >>> ''')
return output_type.strip().lower()
def print_results(self, results: str) -> str:
output: str = c.print(f'''[bold dodger_blue1]
RESULTS:
[bold yellow2]{results}''')
return output
def print_results_table(self, results_dict: dict) -> None:
results_table = Table(
box=box.HORIZONTALS,
show_header=True,
header_style='bold #2070b2',
show_lines=True)
results_table.add_column(
Text('Format', justify='left'),
justify='left',
no_wrap=False)
results_table.add_column(
Text('Encoded String', justify='left'),
justify='left',
ratio=2,
no_wrap=False)
results_table.add_row(
f'[bold green3]Input Value',
f'[bold green3]`{results_dict["input"]}`')
new_dict = {key: value for key, value in results_dict.items() if key not in ['type','input']}
for key, value in new_dict.items():
results_table.add_row(
f'[bright_white]{key}',
f'[khaki1]{value}',
end_section=True)
inner_panel = Panel(
Align.center(
Group(
Align.left(results_table)),
vertical='middle'),
box=box.ROUNDED,
expand=False,
style='none',
border_style='none',
title=f'Convert from {results_dict["type"].upper()} Input',
safe_box=True)
c.print(inner_panel)
def print_results_panels(self, results_dict: dict) -> None:
new_dict = {key: value for key, value in results_dict.items() if key not in ['type','input']}
for key, value in new_dict.items():
rend = [Panel(f'[yellow]{value}',
border_style='blue',
expand=True,
title=f'{key}',
padding=(0,1),
safe_box=True)]
c.print(Columns(rend))