-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
84 lines (73 loc) · 2.82 KB
/
functions.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
import os
import time
line_len = 54
border = '█'
class location():
def __init__(self, loc_data: dict) -> None:
self.title = loc_data['title_screen']['title']
def prompt(location_title: str, prompt_text: str, options: tuple):
while 1 == 1:
text_format(location_title, prompt_text)
formatted_options = opt_format(options)
# input management
print()
selection = input("Type a letter option > ").lower()
if selection in formatted_options.keys():
clear_screen()
# Debug print(formatted_options[selection][1])
return formatted_options[selection][1]
elif selection == "q":
clear_screen()
exit()
else:
print("\033[F", end="")
print("\033[F", end="")
print(selection, "is not a valid option")
time.sleep(2.5)
clear_screen()
def text_format(location:str, text: str):
# Top Border: this will show the current location.
# Subtract location name + 2 white spaces from total line len
bar_amount = int(( line_len - len(location) - 2) / 2)
# If title is even add an extra bar, else it's Gucci
if bar_amount % 2 == 0:
print(border * bar_amount,f"{location}", border * bar_amount, end=f"{border}\n")
else:
print(border * bar_amount,f"{location}", border * bar_amount)
# print(border * line_len)
print(f"{border} {' ':^48} {border}")
# line text formater
words = text.split()
temp_str = ''
# if the current temp string + the next word is <= 50 add the next word into the
# string followed by a space
for value in words:
if len(temp_str + value) + 1 <= 50:
temp_str += value + " "
if value == words[-1]:
print(f"{border} {temp_str:<50} {border}")
else:
# if it's greater than 50 print the line and set the tep string to the current word.
print(f"{border} {temp_str:<50} {border}")
temp_str = value + " "
print(f"{border} {' ':^48} {border}")
print(border * line_len)
def opt_format(options: tuple):
formatted_dict = tup2dict(options)
print(f"{border} {' ':^48} {border}")
for key, selection in formatted_dict.items():
print(f"{border} {key+') '+selection[0]: <50} {border}")
# print(f"{selection[1]}")
print(f"{border} {' ':^48} {border}")
print(border * line_len)
return formatted_dict
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
def tup2dict(option_tup: tuple):
opt_dictionary = {}
letters = [chr(x) for x in range(ord('a'), ord('z') + 1)]
opt_zip = list(zip(letters, option_tup))
for letter, loc_data in opt_zip:
# print(f"{letter}) {loc_data}")
opt_dictionary.update({letter: loc_data})
return opt_dictionary