Classes
TerminalCaps
6
▼
Detected terminal capabilities.
TerminalCaps
6
▼
Detected terminal capabilities.
Attributes
| Name | Type | Description |
|---|---|---|
is_tty |
bool
|
— |
color |
str
|
— |
unicode |
bool
|
— |
width |
int
|
— |
height |
int
|
— |
ambiguous_width |
int
|
— |
Functions
_should_use_colors
0
bool
▼
Check if terminal supports colors and user allows them.
**Respects:**
- NO_COL…
_should_use_colors
0
bool
▼
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.
supports_color
0
bool
▼
def supports_color() -> bool
Returns
bool
colorize
2
str
▼
Apply ANSI color codes to text.
colorize
2
str
▼
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.
strip_colors
1
str
▼
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).
error_code
1
str
▼
def error_code(text: str) -> str
Parameters
| Name | Type | Description |
|---|---|---|
text |
str |
Returns
str
location
1
str
▼
Color text as a file location (cyan).
location
1
str
▼
def location(text: str) -> str
Parameters
| Name | Type | Description |
|---|---|---|
text |
str |
Returns
str
line_number
1
str
▼
Color text as a line number (yellow).
line_number
1
str
▼
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).
error_line
1
str
▼
def error_line(text: str) -> str
Parameters
| Name | Type | Description |
|---|---|---|
text |
str |
Returns
str
hint
1
str
▼
Color text as a hint/suggestion (green).
hint
1
str
▼
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).
suggestion
1
str
▼
def suggestion(text: str) -> str
Parameters
| Name | Type | Description |
|---|---|---|
text |
str |
Returns
str
dim_text
1
str
▼
Color text as dimmed/secondary (dim).
dim_text
1
str
▼
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).
docs_url
1
str
▼
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.
format_error_header
2
str
▼
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.
format_source_line
4
str
▼
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
_detect_terminal_caps
0
TerminalCaps
▼
Detect terminal capabilities from the environment.
_detect_terminal_caps
0
TerminalCaps
▼
def _detect_terminal_caps() -> TerminalCaps
Returns
TerminalCaps
_make_hr_func
2
Callable
▼
Create an ``hr()`` function for terminal templates.
_make_hr_func
2
Callable
▼
def _make_hr_func(width: int, unicode: bool) -> Callable
Parameters
| Name | Type | Description |
|---|---|---|
width |
int |
|
unicode |
bool |
Returns
Callable
_resolve_ambiguous_width
2
int
▼
Resolve the ambiguous character width using a fallback chain.
Resolution order…
_resolve_ambiguous_width
2
int
▼
def _resolve_ambiguous_width(explicit: int | None, is_tty: bool) -> int
Resolve the ambiguous character width using a fallback chain.
Resolution order:
- Explicit user override (
Environment(ambiguous_width=2)) - Terminal probe (queries the actual terminal for rendered width)
wcwidthlibrary (if installed)- Locale heuristic (CJK locale → 2)
- Default: 1
Parameters
| Name | Type | Description |
|---|---|---|
explicit |
int | None |
|
is_tty |
bool |
Returns
int
_init_terminal_mode
5
TerminalCaps
▼
Configure Environment for ``autoescape="terminal"`` mode.
Detects terminal cap…
_init_terminal_mode
5
TerminalCaps
▼
def _init_terminal_mode(env: Any, terminal_color: str | None, terminal_width: int | None, terminal_unicode: bool | None, ambiguous_width: int | None = None) -> TerminalCaps
Configure Environment forautoescape="terminal"mode.
Detects terminal capabilities, applies user overrides, registers
terminal-specific filters and globals. Returns the resolved
TerminalCapsso the caller can store it.
Parameters
| Name | Type | Description |
|---|---|---|
env |
Any |
|
terminal_color |
str | None |
|
terminal_width |
int | None |
|
terminal_unicode |
bool | None |
|
ambiguous_width |
int | None |
Default:None
|
Returns
TerminalCaps