From 7f6b4f7f6ac18893f87d98f81a13d42b9c961031 Mon Sep 17 00:00:00 2001 From: justuser-31 Date: Sat, 7 Mar 2026 13:22:51 +0300 Subject: [PATCH] Add colors for output. --- service.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/service.py b/service.py index e8aad11..3d52389 100644 --- a/service.py +++ b/service.py @@ -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