Coverage for codexa/core/output.py: 89%
18 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-08-10 07:53 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-08-10 07:53 +0000
1import logging
3import click
4from colorama import Fore, Style
7class ColorHandler(logging.StreamHandler):
8 def emit(self, record: logging.LogRecord) -> None:
9 colors = {
10 logging.DEBUG: Fore.CYAN,
11 logging.INFO: Fore.GREEN,
12 logging.WARNING: Fore.YELLOW,
13 logging.ERROR: Fore.RED,
14 logging.CRITICAL: Fore.RED,
15 }
16 color = colors.get(record.levelno, Fore.WHITE)
17 original_levelname = record.levelname
18 try:
19 # Replace levelname with colored version
20 record.levelname = f"{color}{record.levelname}{Style.RESET_ALL}"
21 super().emit(record)
22 finally:
23 # Restore original levelname to avoid side effects
24 record.levelname = original_levelname
27def print_error(message: str) -> None:
28 """
29 Print an error message in red.
31 Args:
32 message (str): The error message to print.
33 """
34 click.echo(f"{Fore.RED}{Style.BRIGHT}{message}{Style.RESET_ALL}")
37def print_warning(message: str) -> None:
38 """
39 Print a warning message in yellow.
41 Args:
42 message (str): The warning message to print.
43 """
44 click.echo(f"{Fore.YELLOW}{Style.BRIGHT}{message}{Style.RESET_ALL}")
47def print_success(message: str) -> None:
48 """
49 Print a success message in green.
51 Args:
52 message (str): The success message to print.
53 """
54 click.echo(f"{Fore.GREEN}{Style.BRIGHT}{message}{Style.RESET_ALL}")