-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsole.py
200 lines (165 loc) · 6.61 KB
/
console.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
from typing import *
class Colors:
RESET = "\033[0m"
BOLD = "\033[1m"
ITALICS = "\033[3m"
UNDERLINE = "\033[4m"
REVERSE = "\033[7m"
BLACK = "\033[0;30m"
RED = "\033[0;31m"
GREEN = "\033[0;32m"
YELLOW = "\033[0;33m"
BLUE = "\033[0;34m"
PURPLE = "\033[0;35m"
CYAN = "\033[0;36m"
WHITE = "\033[0;37m"
BLACK_BOLD = "\033[1;30m"
RED_BOLD = "\033[1;31m"
GREEN_BOLD = "\033[1;32m"
YELLOW_BOLD = "\033[1;33m"
BLUE_BOLD = "\033[1;34m"
PURPLE_BOLD = "\033[1;35m"
CYAN_BOLD = "\033[1;36m"
WHITE_BOLD = "\033[1;37m"
BLACK_ITALICS = "\033[3;30m"
RED_ITALICS = "\033[3;31m"
GREEN_ITALICS = "\033[3;32m"
YELLOW_ITALICS = "\033[3;33m"
BLUE_ITALICS = "\033[3;34m"
PURPLE_ITALICS = "\033[3;35m"
CYAN_ITALICS = "\033[3;36m"
WHITE_ITALICS = "\033[3;37m"
BLACK_UNDERLINED = "\033[4;30m"
RED_UNDERLINED = "\033[4;31m"
GREEN_UNDERLINED = "\033[4;32m"
YELLOW_UNDERLINED = "\033[4;33m"
BLUE_UNDERLINED = "\033[4;34m"
PURPLE_UNDERLINED = "\033[4;35m"
CYAN_UNDERLINED = "\033[4;36m"
WHITE_UNDERLINED = "\033[4;37m"
BLACK_BACKGROUND = "\033[40m"
RED_BACKGROUND = "\033[41m"
GREEN_BACKGROUND = "\033[42m"
YELLOW_BACKGROUND = "\033[43m"
BLUE_BACKGROUND = "\033[44m"
PURPLE_BACKGROUND = "\033[45m"
CYAN_BACKGROUND = "\033[46m"
WHITE_BACKGROUND = "\033[47m"
BLACK_BRIGHT = "\033[0;90m"
RED_BRIGHT = "\033[0;91m"
GREEN_BRIGHT = "\033[0;92m"
YELLOW_BRIGHT = "\033[0;93m"
BLUE_BRIGHT = "\033[0;94m"
PURPLE_BRIGHT = "\033[0;95m"
CYAN_BRIGHT = "\033[0;96m"
WHITE_BRIGHT = "\033[0;97m"
BLACK_BOLD_BRIGHT = "\033[1;90m"
RED_BOLD_BRIGHT = "\033[1;91m"
GREEN_BOLD_BRIGHT = "\033[1;92m"
YELLOW_BOLD_BRIGHT = "\033[1;93m"
BLUE_BOLD_BRIGHT = "\033[1;94m"
PURPLE_BOLD_BRIGHT = "\033[1;95m"
CYAN_BOLD_BRIGHT = "\033[1;96m"
WHITE_BOLD_BRIGHT = "\033[1;97m"
BLACK_BACKGROUND_BRIGHT = "\033[0;100m"
RED_BACKGROUND_BRIGHT = "\033[0;101m"
GREEN_BACKGROUND_BRIGHT = "\033[0;102m"
YELLOW_BACKGROUND_BRIGHT = "\033[0;103m"
BLUE_BACKGROUND_BRIGHT = "\033[0;104m"
PURPLE_BACKGROUND_BRIGHT = "\033[0;105m"
CYAN_BACKGROUND_BRIGHT = "\033[0;106m"
WHITE_BACKGROUND_BRIGHT = "\033[0;107m"
class Console:
@staticmethod
def clear():
print('\033[H\033[2J')
@staticmethod
def color(string: str, col: str) -> str:
return col + string + Colors.RESET
@staticmethod
def print(string: str, col: str = Colors.RESET):
print(Console.color(string, col))
class Prompts:
# my_stuff =
# "╔═══╦═══╦═══╗" +
# "║ ║ ║ ║" +
# "╠═══╬═══╬═══╣" +
# "║ ║ ║ ║" +
# "╚═══╩═══╩═══╝"
@staticmethod
def cn_prompt():
Console.print('Press ENTER to continue...', Colors.RED)
input()
Console.clear()
@staticmethod
def yn_prompt(string: str, op: str):
y = 'Y' if op == 'y' else 'y'
n = 'N' if op == 'n' else 'n'
Console.clear()
Console.print(
Console.color(string + ' [%s/%s]' % (y, n), Colors.RED)
)
while True:
inp = input('> ')
if not inp:
inp = op
if inp.lower() in {'y', 'n'}:
return inp
else:
Console.print('Invalid input.', Colors.RED)
@staticmethod
def num_input(u_bound: int) -> int:
Console.print(f'SELECT AN OPTION [1-{u_bound}]', Colors.CYAN_BOLD)
while True:
try:
x = int(input('> '))
except ValueError:
Console.print('Invalid input.', Colors.RED)
continue
if x in range(1, u_bound + 1):
return x
else:
Console.print('Invalid input.', Colors.RED)
@staticmethod
def q_prompt(prompt: str, op: str):
while True:
inp = input(Console.color(prompt, Colors.BLUE_BOLD))
if inp and Prompts.yn_prompt(inp, op):
return inp
class MenuFormatter:
@staticmethod
def splash():
Console.print(
" _____ _ _ _____ _ _ _____ _ _\n" +
" | _ \| | | | / ____| | (_) / ____| | (_)\n" +
" | |_) | | ___ ___| | _| | | |__ __ _ _ _ __ | | | |__ __ _ _ _ __\n" +
" | _ <| |/ _ \ / __| |/ / | | '_ \ / _` | | '_ \| | | '_ \ / _` | | '_ \\\n" +
" | |_) | | (_) | (__| <| |____| | | | (_| | | | | | |____| | | | (_| | | | | |\n" +
" |____/|_|\___/ \___|_|\_\\\_____|_| |_|\__,_|_|_| |_|\_____|_| |_|\__,_|_|_| |_|\n",
Colors.BLACK_BOLD)
Console.print(
" _,aaaaaaaaaaaaaaaaaaa,_ _,aaaaaaaaaaaaaaaaaaa,_\n" +
" ,P' 'Y, ,P' 'Y,\n" +
" d' ,aaaaaaaaaaaaaaa, `b d' ,aaaaaaaaaaaaaaa, `b\n" +
" d' ,d' ,aaabaaaa8aaaaaaaaaa8aaaadaaa, 'b, `b\n" +
" I I I I I I\n" +
" Y, `Y, `aaaaaaaaaaaaaaaaaaaaaaaaaaaa' ,P' ,P\n" +
" Y, `baaaaaaaaaaaaaaad' ,P Y, `baaaaaaaaaaaaaad' ,P\n" +
" `b, ,d' `b, ,d'\n" +
" `baaaaaaaaaaaaaaaaaaad' `baaaaaaaaaaaaaaaaaaad'\n",
Colors.BLACK_BOLD_BRIGHT)
Console.print(
'Super secret block chain based chain with chains and blocks and crypto and blocks. Also chains.',
Colors.RED_BOLD_BRIGHT)
Console.print(' Developed by: Henry Tu, Yuan Song (Ryan) Zhang, Syed Safwaan, and Andrew Gao \n',
Colors.RED_BOLD)
#Prompts.cn_prompt()
@staticmethod
def option_list(options: Union[List[str], Dict[str, str]]) -> int:
if type(options) is list:
options = {x: Colors.BLACK_BOLD for x in options}
Console.print(f'╔═══╦{"═" * 15}╗', Colors.BLACK_BOLD)
for i, (option, col) in enumerate(options.items(), 1):
Console.print(f'║ {i} ║ {option:<13} ║', col)
Console.print(f'╚═══╩{"═" * 15}╝', Colors.BLACK_BOLD)
return Prompts.num_input(len(options))