|
49 | 49 | PLACEHOLDER_RE = re.compile(r"%\d+") |
50 | 50 | HTML_TAG_RE = re.compile(r"<[^>]+>") |
51 | 51 |
|
52 | | -# ANSI escape codes (Globals) |
53 | | -BOLD, CYAN, YELLOW, RED, RESET = "\033[1m", "\033[36m", "\033[33m", "\033[31m", "\033[0m" |
| 52 | + |
| 53 | +class Colors: |
| 54 | + """ANSI escape codes for terminal output.""" |
| 55 | + BOLD = "\033[1m" |
| 56 | + CYAN = "\033[36m" |
| 57 | + YELLOW = "\033[33m" |
| 58 | + RED = "\033[31m" |
| 59 | + RESET = "\033[0m" |
54 | 60 |
|
55 | 61 |
|
56 | 62 | def configure_colors(color_arg: str): |
57 | 63 | """Disable color constants if outputting to a non-TTY without 'always' override.""" |
58 | | - global BOLD, CYAN, YELLOW, RED, RESET |
59 | 64 | if color_arg == 'never' or (color_arg == 'auto' and not sys.stdout.isatty()): |
60 | | - BOLD = CYAN = YELLOW = RED = RESET = "" |
| 65 | + Colors.BOLD = Colors.CYAN = Colors.YELLOW = Colors.RED = Colors.RESET = "" |
61 | 66 |
|
62 | 67 |
|
63 | 68 | class Severity(IntEnum): |
@@ -214,11 +219,11 @@ def detect_warnings(ts_file: Path, file_lang: str): |
214 | 219 |
|
215 | 220 | def _print_results(grouped): |
216 | 221 | for file in sorted(grouped.keys()): |
217 | | - print(f"\n{BOLD}File: {file.name}{RESET}") |
| 222 | + print(f"\n{Colors.BOLD}File: {file.name}{Colors.RESET}") |
218 | 223 | for w in sorted(grouped[file], key=lambda x: x.line): |
219 | | - color, sev = (RED, "SEVERE ") if w.severity == Severity.SEVERE else (YELLOW, "WARNING") |
| 224 | + color, sev = (Colors.RED, "SEVERE ") if w.severity == Severity.SEVERE else (Colors.YELLOW, "WARNING") |
220 | 225 | lines = w.message.split("\n") |
221 | | - print(f" {CYAN}Line {w.line:<4}{RESET} | {color}{sev}{RESET} | {lines[0]}") |
| 226 | + print(f" {Colors.CYAN}Line {w.line:<4}{Colors.RESET} | {color}{sev}{Colors.RESET} | {lines[0]}") |
222 | 227 | for extra in lines[1:]: |
223 | 228 | print(f" | | {extra}") |
224 | 229 |
|
@@ -252,7 +257,7 @@ def main(): |
252 | 257 |
|
253 | 258 | print("\n== Test Summary ==") |
254 | 259 | for lang in sorted(stats.keys()): |
255 | | - print(f"{BOLD}[{lang}]{RESET} Severe: {stats[lang]['severe']}, " |
| 260 | + print(f"{Colors.BOLD}[{lang}]{Colors.RESET} Severe: {stats[lang]['severe']}, " |
256 | 261 | f"Warnings: {stats[lang]['warning']}") |
257 | 262 |
|
258 | 263 | if sum(s["severe"] for s in stats.values()) > 0 or ( |
|
0 commit comments