-
Notifications
You must be signed in to change notification settings - Fork 325
Expand file tree
/
Copy pathui.py
More file actions
136 lines (101 loc) · 3.8 KB
/
ui.py
File metadata and controls
136 lines (101 loc) · 3.8 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
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
"""
Colorful console UI helpers for Dawn Validator BOT.
"""
from __future__ import annotations
import os
import shutil
from typing import Optional
try:
from colorama import init as colorama_init, Fore, Style
except ImportError: # graceful fallback if dependencies not yet installed
class _Dummy:
RESET_ALL = ""
def __getattr__(self, item: str) -> str:
return ""
def colorama_init(*_: object, **__: object) -> None: # type: ignore[override]
return None
Fore = _Dummy() # type: ignore[assignment]
Style = _Dummy() # type: ignore[assignment]
colorama_init(autoreset=True)
def clear() -> None:
"""Clear the console screen."""
os.system("cls" if os.name == "nt" else "clear")
def get_terminal_width(default: int = 80) -> int:
"""Best-effort terminal width detection."""
try:
return shutil.get_terminal_size().columns
except Exception:
return default
def hr(char: str = "━") -> str:
"""Horizontal rule matching terminal width."""
width = max(40, get_terminal_width())
return char * width
def colored(text: str, *, fg: Optional[str] = None, bright: bool = False) -> str:
"""Return text wrapped in color/brightness styles."""
parts = []
if bright:
parts.append(Style.BRIGHT)
if fg:
parts.append(fg)
parts.append(text)
parts.append(Style.RESET_ALL)
return "".join(parts)
def print_logo() -> None:
"""Print the Dawn Validator BOT logo with a light gradient effect."""
logo_lines = [
r"/$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$$",
r"| $$__ $$ | $$__ $$ /$$__ $$|__ $$__/",
r"| $$ \ $$ /$$$$$$ /$$ /$$ /$$ /$$$$$$$ | $$ \ $$| $$ \ $$ | $$ ",
r"| $$ | $$ |____ $$| $$ | $$ | $$| $$__ $$ /$$$$$$| $$$$$$$ | $$ | $$ | $$ ",
r"| $$ | $$ /$$$$$$$| $$ | $$ | $$| $$ \ $$|______/| $$__ $$| $$ | $$ | $$ ",
r"| $$ | $$ /$$__ $$| $$ | $$ | $$| $$ | $$ | $$ \ $$| $$ | $$ | $$ ",
r"| $$$$$$$/| $$$$$$$| $$$$$/$$$$/| $$ | $$ | $$$$$$$/| $$$$$$/ | $$ ",
r"|_______/ \_______/ \_____/\___/ |__/ |__/ |_______/ \______/ |__/",
]
palette = [
Fore.CYAN,
Fore.BLUE,
Fore.MAGENTA,
Fore.CYAN,
Fore.BLUE,
Fore.MAGENTA,
Fore.CYAN,
Fore.BLUE,
]
print()
for idx, line in enumerate(logo_lines):
color = palette[idx % len(palette)]
print(colored(line, fg=color, bright=True))
print()
def print_title(title: str) -> None:
"""Print a colored title block."""
print(colored(hr(), fg=Fore.MAGENTA, bright=True))
print(colored(f" {title} ", fg=Fore.CYAN, bright=True))
print(colored(hr(), fg=Fore.MAGENTA, bright=True))
def print_menu(options: list[str]) -> None:
"""Render a numbered menu."""
for idx, option in enumerate(options, start=1):
print(
colored(
f"[{idx}] ",
fg=Fore.YELLOW,
bright=True,
)
+ colored(option, fg=Fore.WHITE, bright=False)
)
print(
colored("[0] ", fg=Fore.RED, bright=True)
+ colored("Exit", fg=Fore.WHITE)
)
print()
def prompt_choice(prompt: str = "Select menu option") -> str:
"""Prompt user for a menu choice."""
return input(colored(f"{prompt}: ", fg=Fore.CYAN, bright=True))
def info(msg: str) -> None:
print(colored(msg, fg=Fore.GREEN, bright=True))
def warn(msg: str) -> None:
print(colored(msg, fg=Fore.YELLOW, bright=True))
def error(msg: str) -> None:
print(colored(msg, fg=Fore.RED, bright=True))
def pause(msg: str = "Press Enter to continue...") -> None:
input(colored(msg, fg=Fore.CYAN))