From 2be1eb8fdc15e6e34ce3d4702542ebacde33e7f1 Mon Sep 17 00:00:00 2001 From: CodeDevMLH Date: Tue, 10 Dec 2024 02:19:58 +0100 Subject: [PATCH] add colored output --- customize-WebUI.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/customize-WebUI.py b/customize-WebUI.py index 30aa3c5..cd5bb46 100644 --- a/customize-WebUI.py +++ b/customize-WebUI.py @@ -4,6 +4,13 @@ import yaml import re import sys +# ANSI escape sequences for colors +class Colors: + CYAN = '\033[96m' + GREEN = '\033[92m' + YELLOW = '\033[93m' + RED = '\033[91m' + RESET = '\033[0m' # Global variable to track errors errorList = {"copies": 0, "modifications": 0, "copyWarnings": 0, "modWarnings": 0} @@ -134,7 +141,7 @@ def copySources(config, destinationDirectory): errorList["copies"] += 1 continue - print(f"\nSource file & folder copy/replace process completed with {errorList['copies']} errors and {errorList['copyWarnings']} warnings.\n") + print(f"\nSource file & folder copy/replace process completed with {Colors.RED}{errorList['copies']} errors{Colors.RESET} and {Colors.YELLOW}{errorList['copyWarnings']} warnings{Colors.RESET}.\n") def modifyFiles(config, destinationDirectory): @@ -218,7 +225,7 @@ def modifyFiles(config, destinationDirectory): errorList["modifications"] += 1 continue - print(f"\nFile modification process completed with {errorList['modifications']} errors and {errorList['modWarnings']} warnings.\n") + print(f"\nFile modification process completed with {Colors.RED}{errorList['modifications']} errors{Colors.RESET} and {Colors.YELLOW}{errorList['modWarnings']} warnings{Colors.RESET}.\n") def main(): @@ -244,17 +251,17 @@ def main(): modifyFiles(config, destinationDirectory) # Print results - print(f'\nTotal successful copies: {results["copies"]}') - print(f'Total file modifications: {results["modifications"]}') + print(f'\n{Colors.GREEN}Total successful copies: {results["copies"]}') + print(f'Total file modifications: {results["modifications"]}{Colors.RESET}') if errorList["copies"] > 0 or errorList["modifications"] > 0: - print("Errors occurred during the process. Check the output for details.") + print(f"{Colors.RED}Errors occurred during the process. Check the output for details.") print(f"Total copy errors: {errorList['copies']}") - print(f"Total modification errors: {errorList['modifications']}") + print(f"Total modification errors: {errorList['modifications']}{Colors.RESET}") elif errorList["copyWarnings"] > 0 or errorList["modWarnings"] > 0: - print(f"All operations in {destinationDirectory} from {configPath} completed successfully! But there were {errorList['modWarnings'] + errorList['copyWarnings']} warnings. Mybe you should check them.") + print(f"{Colors.YELLOW}All operations in {destinationDirectory} from {configPath} completed successfully! But there were {errorList['modWarnings'] + errorList['copyWarnings']} warnings. Maybe you should check them.{Colors.RESET}") else: - print(f"All operations in {destinationDirectory} from {configPath} completed successfully!") + print(f"{Colors.GREEN}All operations in {destinationDirectory} from {configPath} completed successfully!{Colors.RESET}") if __name__ == '__main__':