formatters
Color formatting utilities for terminal output with auto-detection.
_colorize(text, color)
Apply color to text if colors are enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to colorize |
required |
color
|
str
|
ANSI color code |
required |
Returns:
| Type | Description |
|---|---|
str
|
Colorized text if colors enabled, otherwise plain text |
Source code in src/sparkwheel/errors/formatters.py
_get_colors_enabled()
Get current color enable status, initializing if needed.
Source code in src/sparkwheel/errors/formatters.py
_supports_color()
Auto-detect if the terminal supports colors.
Follows industry standards for color detection: 1. NO_COLOR environment variable disables colors (https://no-color.org/) 2. SPARKWHEEL_NO_COLOR environment variable disables colors (sparkwheel-specific) 3. FORCE_COLOR environment variable enables colors (https://force-color.org/) 4. stdout TTY detection (auto-detect) 5. Default: disable colors
Returns:
| Type | Description |
|---|---|
bool
|
True if colors should be enabled, False otherwise |
Source code in src/sparkwheel/errors/formatters.py
enable_colors(enabled=None)
Enable or disable color output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool | None
|
True to enable, False to disable, None for auto-detection |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
Current color enable status |
Examples:
>>> enable_colors(False) # Disable colors
False
>>> enable_colors(True) # Force enable colors
True
>>> enable_colors() # Auto-detect
True # (if terminal supports it)
Source code in src/sparkwheel/errors/formatters.py
format_bold(text)
Format text as bold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted text |
format_code(text)
Format text as code/metadata (blue).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted text |
format_context(text)
Format text as context (gray).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted text |
format_error(text)
Format text as an error (red).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted text |
Examples:
>>> format_error("Error message")
'[31mError message[0m' # With colors enabled
>>> format_error("Error message")
'Error message' # With colors disabled
Source code in src/sparkwheel/errors/formatters.py
format_success(text)
Format text as success/correct (green).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted text |
format_suggestion(text)
Format text as a suggestion (yellow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text to format |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted text |