Module

environment.terminal

Terminal color utilities for rich error messages.

Provides ANSI color codes with automatic TTY detection and NO_COLOR support. Simple, zero-dependency implementation for beautiful error output.

Functions

_should_use_colors 0 bool
Check if terminal supports colors and user allows them. **Respects:** - NO_COL…
def _should_use_colors() -> bool

Check if terminal supports colors and user allows them.

Respects:

  • NO_COLOR environment variable (https://no-color.org/)
  • FORCE_COLOR environment variable (overrides NO_COLOR)
  • sys.stdout.isatty() for TTY detection
Returns
bool
supports_color 0 bool
Check if current terminal supports color output.
def supports_color() -> bool
Returns
bool
colorize 2 str
Apply ANSI color codes to text.
def colorize(text: str, *colors: ColorName) -> str
Parameters
Name Type Description
text str

Text to colorize *colors: One or more color names to apply

*colors ColorName
Returns
str
strip_colors 1 str
Remove ANSI color codes from text.
def strip_colors(text: str) -> str
Parameters
Name Type Description
text str

Text potentially containing ANSI codes

Returns
str
error_code 1 str
Color text as an error code (bright red + bold).
def error_code(text: str) -> str
Parameters
Name Type Description
text str
Returns
str
location 1 str
Color text as a file location (cyan).
def location(text: str) -> str
Parameters
Name Type Description
text str
Returns
str
line_number 1 str
Color text as a line number (yellow).
def line_number(text: str) -> str
Parameters
Name Type Description
text str
Returns
str
error_line 1 str
Color text as an error line (bright red).
def error_line(text: str) -> str
Parameters
Name Type Description
text str
Returns
str
hint 1 str
Color text as a hint/suggestion (green).
def hint(text: str) -> str
Parameters
Name Type Description
text str
Returns
str
suggestion 1 str
Color text as a 'Did you mean?' suggestion (bright_green + bold).
def suggestion(text: str) -> str
Parameters
Name Type Description
text str
Returns
str
dim_text 1 str
Color text as dimmed/secondary (dim).
def dim_text(text: str) -> str
Parameters
Name Type Description
text str
Returns
str
docs_url 1 str
Color text as a documentation URL (bright_blue).
def docs_url(text: str) -> str
Parameters
Name Type Description
text str
Returns
str
format_error_header 2 str
Format error header with optional code.
def format_error_header(code: str | None, message: str) -> str
Parameters
Name Type Description
code str | None

Optional error code (e.g., "K-RUN-001")

message str

Error message

Returns
str
format_source_line 4 str
Format a source line with colors.
def format_source_line(lineno: int, content: str, is_error: bool = False, show_marker: bool = True) -> str
Parameters
Name Type Description
lineno int

Line number

content str

Line content

is_error bool

True if this is the error line

Default:False
show_marker bool

True to show '>' marker for error line

Default:True
Returns
str