1010from pathlib import Path
1111from jsonschema import Draft7Validator
1212
13+ # Global switch to control whether ANSI colors are used in output.
14+ # This is controlled from CLI via the `--no-color` flag.
15+ ENABLE_COLOR = True
16+
17+
18+ def set_color_enabled (enabled : bool ):
19+ """Enable or disable ANSI color output.
20+
21+ Args:
22+ enabled: If False, all helper output functions will omit ANSI
23+ escape sequences.
24+ """
25+
26+ global ENABLE_COLOR
27+ ENABLE_COLOR = enabled
28+
1329
1430def print_header (header : str ):
1531 """Print a simple boxed header to stdout.
@@ -39,10 +55,14 @@ def format_status(message: str, validated: bool = False):
3955 red "Failed".
4056 """
4157
58+ if not ENABLE_COLOR :
59+ result = "Passed" if validated else "Failed"
60+ return f"{ message } { result } "
61+
4262 # ANSI color codes used for terminal output
4363 if not validated :
4464 result = "\033 [31mFailed\033 [0m" # red
45- elif validated :
65+ else :
4666 result = "\033 [32mPassed\033 [0m" # green
4767
4868 return f"{ message } { result } "
@@ -51,6 +71,9 @@ def format_status(message: str, validated: bool = False):
5171def info_message (message : str ):
5272 """format to blue color and return the message string."""
5373
74+ if not ENABLE_COLOR :
75+ return message
76+
5477 return f"\033 [34m{ message } \033 [0m"
5578
5679
@@ -69,6 +92,10 @@ def log_message(message: str, status: int = 0):
6992 (success).
7093 """
7194
95+ if not ENABLE_COLOR :
96+ print (message )
97+ return
98+
7299 colors = {- 1 : "\033 [31m" , 1 : "\033 [32m" }
73100 color = colors .get (status , "" )
74101 reset = "\033 [0m" if color else ""
@@ -143,6 +170,9 @@ def logError(label: str, path: str, message: str):
143170 single formatted string instead of printing directly.
144171 """
145172
173+ if not ENABLE_COLOR :
174+ return f"{ label } : { path } → { message } "
175+
146176 return f"\033 [31m{ label } : { path } → { message } \033 [0m"
147177
148178
0 commit comments