fitzzftw.patch.base.TerminalColorMixin¶
- class TerminalColorMixin[source]¶
Bases:
objectProvides colorization capabilities for CLI output.
The mixin provides a
colorize()method to encapsulate strings with ANSI color codes and bold styling.Public Data Attributes:
Global toggle to enable or disable colorized output.
Public Methods:
colorize(text, color_key[, bold])Colorizes the text using ANSI escape sequences.
print(**kwargs)Prints the line with color mapping based on its prefix.
Private Data Attributes:
Internal mapping of semantic names to ANSI escape sequences.
- _ANSI: Color = <fitzzftw.patch.static.Color object>¶
Internal mapping of semantic names to ANSI escape sequences. Can be overridden for testing purposes.
- colorize(text, color_key, bold=False, **kwargs)[source]¶
Colorizes the text using ANSI escape sequences.
- Parameters:
text (str) – The string to colorize.
color_key ('red' | 'green' | 'yellow' | 'cyan' | 'terminal') – The color to use (‘red’, ‘green’, ‘cyan’).
bold (bool) – Whether to make the output bold.
kwargs – Arbitrary keyword arguments forwarded to the built-in print() function. This allows for fine-grained control over the output, such as specifying a custom ‘file’ stream or changing the line termination via ‘end’ (e.g., end=”|”).
- Returns:
Colorized string or plain text if colors are disabled.
- Return type:
None
- print(**kwargs)[source]¶
Prints the line with color mapping based on its prefix.
- Raises:
FtwProtocolError – If the class does not satisfy the LineLike protocol.
- Parameters:
kwargs – Passed to colorize/print (e.g., end, file).