forked from TarlogicSecurity/BlueSpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.py
61 lines (46 loc) · 1.13 KB
/
interface.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
#!/usr/bin/env python3
"""
Logging and text interface related code.
"""
class bcolors:
HEADER = "\033[34m"
OK_BLUE = "\033[94m"
OK_CYAN = "\033[96m"
OK_GREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
class loglevel:
INFO = ("I", bcolors.OK_GREEN)
WARN = ("!", bcolors.WARNING)
INPUT = ("?", bcolors.OK_BLUE)
DEBUG = ("D", bcolors.OK_BLUE)
def color_print(color: bcolors, msg: str):
"""
Print a string with the selected color.
"""
print(f"{color}{msg}{bcolors.ENDC}")
def log(level: loglevel, msg: str):
"""
Print a string with the selected log level.
"""
print(f"[{level[1]}{level[0]}{bcolors.ENDC}] {msg}")
def log_info(msg: str):
"""
Print an info string.
"""
log(loglevel.INFO, msg)
def log_warn(msg: str):
"""
Print a warning string.
"""
log(loglevel.WARN, msg)
def input_yn(msg: str) -> bool:
"""
Get a yes/no answer to a prompt.
"""
log(loglevel.INPUT, msg)
option = input("[Y/n] ") or "y"
return option.lower() in ("y", "yes")