-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.py
More file actions
83 lines (74 loc) · 3.64 KB
/
Copy pathconsole.py
File metadata and controls
83 lines (74 loc) · 3.64 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
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
import os
import sys
from colorama import init as colorama_init
from colorama import Fore
from colorama import Style
from constants import VERSION
if os.name == 'nt': # Windows
import msvcrt
else:
import tty
import termios
colorama_init()
# === Console Actions ===
# Clears screen
def clearscreen():
if os.name == 'nt': # Windows
os.system('cls')
else:
os.system('clear')
# Reads for keypress
def read_single_keypress():
if os.name == 'nt': # Windows
first_byte = msvcrt.getch()
if first_byte in (b'\xe0', b'\x00'):
second_byte = msvcrt.getch()
return first_byte + second_byte
else:
return first_byte
else:
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
key = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return key
# Displays a menu with arrow keys for navigation
def display_menu(options, selected_index, written=False):
while True:
if written:
print(f"\033[{str(1+len(options))}A")
else:
written = True
for i, option in enumerate(options):
if i == selected_index:
print(f" {Fore.CYAN}>> {option}{Style.RESET_ALL}{" " * 10}")
else:
print(f" {option}{Style.RESET_ALL}{" " * 10}")
key = read_single_keypress()
if key in [b'\x1b[A', b'\xe0H', b'\x00H', b'H']: # Up arrow key
selected_index = (selected_index - 1) % len(options)
elif key in [b'\x1b[B', b'\xe0P', b'\x00P', b'P']: # Down arrow key
selected_index = (selected_index + 1) % len(options)
elif key in ['\r', '\n', b'\r']:
break
return selected_index
# === Console Graphics ===
# ASCII Art for main title
def show_title(page: str):
print("")
print(" ______ __ ________ __ __ ______ __ ".replace("$", Fore.GREEN + "$" + Style.RESET_ALL))
print(" / \\ | \\ | \\ | \\| \\ / \\ | \\ ".replace("$", Fore.GREEN + "$" + Style.RESET_ALL))
print("| $$$$$$\\ __ __ _| $$_ ______ | $$$$$$$$ ______ ____ ______ \\$$| $$| $$$$$$\\ ______ _______ ____| $$ ______ ".replace("$", Fore.GREEN + "$" + Style.RESET_ALL))
print("| $$__| $$| \\ | \\| $$ \\ / \\ | $$__ | \\ \\ | \\ | \\| $$| $$___\\$$ / \\ | \\ / $$ / \\ ".replace("$", Fore.GREEN + "$" + Style.RESET_ALL))
print("| $$ $$| $$ | $$ \\$$$$$$ | $$$$$$\\| $$ \\ | $$$$$$\\$$$$\\ \\$$$$$$\\| $$| $$ \\$$ \\ | $$$$$$\\| $$$$$$$\\| $$$$$$$| $$$$$$\\".replace("$", Fore.GREEN + "$" + Style.RESET_ALL))
print("| $$$$$$$$| $$ | $$ | $$ __ | $$ | $$| $$$$$ | $$ | $$ | $$ / $$| $$| $$ _\\$$$$$$\\| $$ $$| $$ | $$| $$ | $$| $$ \\$$".replace("$", Fore.GREEN + "$" + Style.RESET_ALL))
print("| $$ | $$| $$__/ $$ | $$| \\| $$__/ $$| $$_____ | $$ | $$ | $$| $$$$$$$| $$| $$| \\__| $$| $$$$$$$$| $$ | $$| $$__| $$| $$ ".replace("$", Fore.GREEN + "$" + Style.RESET_ALL))
print("| $$ | $$ \\$$ $$ \\$$ $$ \\$$ $$| $$ \\| $$ | $$ | $$ \\$$ $$| $$| $$ \\$$ $$ \\$$ \\| $$ | $$ \\$$ $$| $$ ".replace("$", Fore.GREEN + "$" + Style.RESET_ALL))
print(" \\$$ \\$$ \\$$$$$$ \\$$$$ \\$$$$$$ \\$$$$$$$$ \\$$ \\$$ \\$$ \\$$$$$$$ \\$$ \\$$ \\$$$$$$ \\$$$$$$$ \\$$ \\$$ \\$$$$$$$ \\$$ ".replace("$", Fore.GREEN + "$" + Style.RESET_ALL))
print("")
print((" " * 127) + VERSION)
print(Fore.CYAN + (" " * int((((133-len(page))/2) - 4))) + "- [ " + page + " ] -" + Style.RESET_ALL)
print("")