-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_console.py
More file actions
91 lines (81 loc) · 3.2 KB
/
custom_console.py
File metadata and controls
91 lines (81 loc) · 3.2 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
"""
Custom Module for Console Log formats,
like Colors, Loading Indicators, etc
Something similar to https://rich.readthedocs.io/en/stable/introduction.html
"""
import sys
import time
import os
# ANSI escape codes for colors, etc, in print statements
COLOR_RED = "\033[91m" # Bright Red
COLOR_GREEN = "\033[92m" # Bright Green
COLOR_YELLOW = "\033[93m" # Bright Yellow
COLOR_BLUE = "\033[94m" # Bright Blue
COLOR_MAGENTA = "\033[95m"# Bright Magenta
COLOR_CYAN = "\033[96m" # Bright Cyan
COLOR_WHITE = "\033[97m" # Bright White
RESET_COLOR = "\033[0m" # Reset to default color and formatting
# Clear console log
def clear_console():
"""Clears the console screen based on the operating system."""
os.system('cls' if os.name == 'nt' else 'clear')
# Loading Spinners
def simple_initializer_spinner(duration=3, msg="Loading Complete!"):
"""
Displays a Spinner Indicator that appears to animation over time.
"""
spinner_chars = ['-', '\\', '|', '/'] # Characters for the spinner
start_time = time.time()
i = 0
while time.time() - start_time < duration:
sys.stdout.write(f'\r{COLOR_MAGENTA}Loading {spinner_chars[i % len(spinner_chars)]}')
sys.stdout.flush()
time.sleep(0.1) # Controls the speed of the spin
i += 1
sys.stdout.write(f'{COLOR_GREEN}\r{msg}') # Overwrite with final message and a newline
sys.stdout.flush()
print(f'{RESET_COLOR}')
def simple_spinner(duration=3, msg="Loading Complete!"):
"""
Displays a Spinner Indicator that appears to animation over time.
"""
spinner_chars = ['-', '\\', '|', '/'] # Characters for the spinner
start_time = time.time()
i = 0
while time.time() - start_time < duration:
sys.stdout.write(f'\r{COLOR_MAGENTA}Loading {spinner_chars[i % len(spinner_chars)]}')
sys.stdout.flush()
time.sleep(0.1) # Controls the speed of the spin
i += 1
# Overwrite with final message and a newline
sys.stdout.write(f'{COLOR_CYAN}\r{msg}')
sys.stdout.flush()
print(f'{RESET_COLOR}')
# Timers
"""
Tracking the time taken for processes, e.i functions, to complete.
This is useful for debugging and performance monitoring.
"""
from datetime import datetime
# Start timer
# End timer
# TODO: "Add Minutes/Hours"
def process_timer_elapsed_time_success():
"""Returns the elapsed time since the start."""
print(f"\n✅ {COLOR_GREEN}Completed in {time.time() - start_time:.2f} seconds{RESET_COLOR}\n")
print(f"{COLOR_GREEN}██████████████████{RESET_COLOR}\n")
print(rf"""
|
____________ __ {COLOR_GREEN}-+-{RESET_COLOR} ____________
\_____ / /_ \{COLOR_GREEN} |{RESET_COLOR} \ _____/
\_____ \____/ \____/ _____/
\_____ _____/
\___________ ___________/
/____\\
""")
return time.time() - start_time
def process_timer_elapsed_time_failure():
"""Returns the elapsed time since the start."""
print(f"\n❌ {COLOR_RED}Completed in {time.time() - start_time:.2f} seconds{RESET_COLOR}\n")
print(f"{COLOR_RED}██████████████████{RESET_COLOR}\n")
return time.time() - start_time