Add colors for output.

This commit is contained in:
justuser-31 2026-03-07 13:22:51 +03:00
parent 665fbed920
commit 7f6b4f7f6a

View File

@ -9,6 +9,12 @@ PID_FILE = Path("pid.txt")
MAIN_SCRIPT = "main.py"
START_DELAY = 0.3
# ANSI color codes
RED = "\033[91m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RESET = "\033[0m"
def display_help():
print(
@ -47,20 +53,20 @@ def start_process():
def cmd_status():
pid = get_pid()
if pid:
print(f"[Running] PID: {pid}")
print(f"{GREEN}[Running] PID: {pid}{RESET}")
return 0
print("[Stopped]")
print(f"{RED}[Stopped]{RESET}")
return 1
def cmd_start():
if pid := get_pid():
print(f"Already running with PID: {pid}")
print(f"{YELLOW}Already running with PID: {pid}{RESET}")
return 2
if pid := start_process():
print(f"Started with PID: {pid}")
print(f"{GREEN}Started with PID: {pid}{RESET}")
return 0
print(f"Can't get PID... Crash? | CWD: {os.getcwd()}")
print(f"{RED}Can't get PID... Crash? | CWD: {os.getcwd()}{RESET}")
return 1
@ -68,14 +74,14 @@ def cmd_stop():
pid = get_pid()
clear_pid()
if not pid:
print(f"Process already stopped. | CWD: {os.getcwd()}")
print(f"{YELLOW}Process already stopped. | CWD: {os.getcwd()}{RESET}")
return 2
try:
os.kill(pid, signal.SIGTERM) # Graceful shutdown vs SIGKILL
print("Process successfully stopped.")
print(f"{GREEN}Process successfully stopped.{RESET}")
return 0
except ProcessLookupError:
print(f"Process already stopped. | CWD: {os.getcwd()}")
print(f"{YELLOW}Process already stopped. | CWD: {os.getcwd()}{RESET}")
return 2
@ -88,9 +94,9 @@ def cmd_restart():
pass
clear_pid()
if pid := start_process():
print(f"Restarted with PID: {pid}")
print(f"{GREEN}Restarted with PID: {pid}{RESET}")
return 0
print(f"Can't get PID... Crash? | CWD: {os.getcwd()}")
print(f"{RED}Can't get PID... Crash? | CWD: {os.getcwd()}{RESET}")
return 1