Terminal module¶
- Terminal.ansi_to_wwiv(text: str, reset_code: str = '|07') str[source]¶
Convierte ANSI SGR (ESC[…m) a WWIV pipe codes |NN.
Reset (0) => reset_code (por defecto |07 = Gray)
Soporta fg 30-37/90-97 y bg 40-47.
Si viene “1” (bold), lo tratamos como ‘bright’ si hay fg 30-37.
- class Terminal.AnsiColors(value)[source]¶
Bases:
EnumAnsiColors Enum for managing ANSI escape codes for terminal styling.
This class provides an organized way to use ANSI escape codes for adding colors and styles to terminal output. The escape codes can be used to set foreground colors, styles (like bold), and reset the formatting.
- RESET¶
Resets all formatting to the default.
- BOLD¶
Makes the text bold.
- BLACK¶
Sets the text color to black.
- RED¶
Sets the text color to red.
- GREEN¶
Sets the text color to green.
- YELLOW¶
Sets the text color to yellow.
- BLUE¶
Sets the text color to blue.
- MAGENTA¶
Sets the text color to magenta.
- CYAN¶
Sets the text color to cyan.
- WHITE¶
Sets the text color to white.
- BRIGHT_BLACK¶
Sets the text color to bright black (gray).
- BRIGHT_RED¶
Sets the text color to bright red.
- BRIGHT_GREEN¶
Sets the text color to bright green.
- BRIGHT_YELLOW¶
Sets the text color to bright yellow.
- BRIGHT_BLUE¶
Sets the text color to bright blue.
- BRIGHT_MAGENTA¶
Sets the text color to bright magenta.
- BRIGHT_CYAN¶
Sets the text color to bright cyan.
- BRIGHT_WHITE¶
Sets the text color to bright white.
- Usage:
To apply a color, use the value property of the Enum member. For example:
print(f”{AnsiColors.BRIGHT_GREEN.value}This text is bright green!{AnsiColors.RESET.value}”)
Note
Ensure your terminal supports ANSI escape codes to see the styling correctly. Most modern terminals (Linux, macOS, and many on Windows) support ANSI codes.
- RESET = '\x1b[0m'¶
- BOLD = '\x1b[1m'¶
- BLACK = '\x1b[0;30m'¶
- RED = '\x1b[0;31m'¶
- GREEN = '\x1b[0;32m'¶
- YELLOW = '\x1b[0;33m'¶
- BLUE = '\x1b[0;34m'¶
- MAGENTA = '\x1b[0;35m'¶
- CYAN = '\x1b[0;36m'¶
- WHITE = '\x1b[0;37m'¶
- BRIGHT_BLACK = '\x1b[1;30m'¶
- BRIGHT_RED = '\x1b[1;31m'¶
- BRIGHT_GREEN = '\x1b[1;32m'¶
- BRIGHT_YELLOW = '\x1b[1;33m'¶
- BRIGHT_BLUE = '\x1b[1;34m'¶
- BRIGHT_MAGENTA = '\x1b[1;35m'¶
- BRIGHT_CYAN = '\x1b[1;36m'¶
- BRIGHT_WHITE = '\x1b[1;37m'¶
- P1_AMBAR = '#FFB000'¶
- P1_LIGHT_AMBAR = '#FFCC00'¶
- P1_GREEN = '#33FF00'¶
- P1_WHITE = '#282828'¶
- class Terminal.TerminalIcons(value)[source]¶
Bases:
EnumIcons used in the terminal interface.
- ERROR: str = '‼️ '¶
- INFO: str = 'ℹ️ '¶
- SUCCESS: str = '✅ '¶
- WARNING: str = '⚠️ '¶
- class Terminal.Terminal(default_color: str = 'white', color_mode: str = 'ansi')[source]¶
Bases:
objectClass for styled terminal messages.
- __init__(default_color: str = 'white', color_mode: str = 'ansi')[source]¶
Initialize the Terminal class with a default color and color mode. :param default_color: Default color for messages. Defaults to ‘white’. :type default_color: str :param color_mode: ‘ansi’ (default), ‘wwiv’, or ‘none’. :type color_mode: str