-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathprompts.py
64 lines (53 loc) · 1.78 KB
/
prompts.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
import sys
import os
if os.name == 'nt':
os.system("color")
class Colors:
HEADER = '\033[95m'
BLUE = '\033[94m'
MAGENTA = '\033[35m'
CYAN = '\033[96m'
GREEN = '\033[92m'
YELLOW = '\033[33m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
class Prompt:
@staticmethod
def error(message, close=False):
print(f"{Colors.FAIL}[x]{message}{Colors.ENDC}")
if close:
sys.exit(1)
@staticmethod
def banner(items, prevent_all_option=False):
for i, item in enumerate(items):
print(f"{Colors.WARNING}{i+1}. {Colors.CYAN}{item}{Colors.ENDC}")
if not prevent_all_option and len(items) > 1:
print(f"{Colors.WARNING}{len(items) + 1}. All{Colors.ENDC}")
return items
@staticmethod
def get_response(prompt, items, prevent_all_option=False):
print()
value = input(prompt)
if value not in [str(x + 1) for x in range(len(items) + 1 if (not prevent_all_option and len(items) > 1)
else len(items))] or int(value) == len(items) + 1:
Prompt.error(f"{value} is not a valid choice.")
return Prompt.get_response(prompt, items)
return int(value)
@staticmethod
def question_banner(title, first=False):
if not first:
print()
print(f"{Colors.HEADER}[-]{title}{Colors.ENDC}")
print("="*35)
@staticmethod
def warning(message):
print(f"{Colors.WARNING}[-]{message}{Colors.ENDC}")
@staticmethod
def notice(message):
print(f"{Colors.YELLOW}[*]{message}{Colors.ENDC}")
@staticmethod
def success(message):
print(f"{Colors.GREEN}[+]{message}{Colors.ENDC}")