|
import time
|
|
import threading
|
|
|
|
|
|
class Colors:
|
|
RESET = "\x1b[0m"
|
|
BOLD = "\x1b[1m"
|
|
RED = "\x1b[91m"
|
|
GREEN = "\x1b[92m"
|
|
YELLOW = "\x1b[93m"
|
|
BLUE = "\x1b[94m"
|
|
MAGENTA = "\x1b[95m"
|
|
CYAN = "\x1b[96m"
|
|
GRAY = "\x1b[90m"
|
|
WHITE = "\x1b[97m"
|
|
BG_BLUE = "\x1b[44m"
|
|
BG_GREEN = "\x1b[42m"
|
|
BG_RED = "\x1b[41m"
|
|
|
|
|
|
class Spinner:
|
|
|
|
def __init__(self, message="Processing...", spinner_chars="|/-\\"):
|
|
self.message = message
|
|
self.spinner_chars = spinner_chars
|
|
self.running = False
|
|
self.thread = None
|
|
|
|
def start(self):
|
|
self.running = True
|
|
self.thread = threading.Thread(target=self._spin)
|
|
self.thread.start()
|
|
|
|
def stop(self):
|
|
self.running = False
|
|
if self.thread:
|
|
self.thread.join()
|
|
print("\r" + " " * (len(self.message) + 2) + "\r", end="", flush=True)
|
|
|
|
def _spin(self):
|
|
i = 0
|
|
while self.running:
|
|
char = self.spinner_chars[i % len(self.spinner_chars)]
|
|
print(f"\r{Colors.CYAN}{char}{Colors.RESET} {self.message}", end="", flush=True)
|
|
i += 1
|
|
time.sleep(0.1)
|