Classes
Styled
10
▼
A string subclass marking content as already styled with ANSI codes.
The Styled class implements t…
Styled
10
▼
A string subclass marking content as already styled with ANSI codes.
The Styled class implements the__terminal__protocol used by the
template engine to identify pre-sanitized terminal content. When combined
with regular strings via operators like+, the non-Styled strings are
automatically sanitized.
This is the terminal-mode analogue ofMarkupfor HTML mode.
Methods
format
2
Self
▼
Format string, sanitizing non-Styled arguments.
format
2
Self
▼
def format(self, *args: Any, **kwargs: Any) -> Self
Parameters
| Name | Type | Description |
|---|---|---|
*args |
— |
|
**kwargs |
— |
Returns
Self
join
1
Self
▼
Join sequence, sanitizing non-Styled elements.
join
1
Self
▼
def join(self, seq: Iterable[str]) -> Self
Parameters
| Name | Type | Description |
|---|---|---|
seq |
— |
Returns
Self
Internal Methods 8 ▼
__new__
1
Self
▼
Create a Styled string.
__new__
1
Self
▼
def __new__(cls, value: Any = '') -> Self
Parameters
| Name | Type | Description |
|---|---|---|
value |
— |
Content to mark as safe. If it has a ''
|
Returns
Self
Styled instance containing the safe content.
__terminal__
0
Self
▼
Return self -- already safe content.
This method is the ``__terminal__`` proto…
__terminal__
0
Self
▼
def __terminal__(self) -> Self
Return self -- already safe content.
This method is the__terminal__protocol that the template engine
uses to detect pre-sanitized terminal content.
Returns
Self
__repr__
0
str
▼
__repr__
0
str
▼
def __repr__(self) -> str
Returns
str
__add__
1
Self
▼
Concatenate, sanitizing ``other`` if not Styled.
__add__
1
Self
▼
def __add__(self, other: str) -> Self
Parameters
| Name | Type | Description |
|---|---|---|
other |
— |
Returns
Self
__radd__
1
Self
▼
Reverse concatenate, sanitizing ``other`` if not Styled.
__radd__
1
Self
▼
def __radd__(self, other: str) -> Self
Parameters
| Name | Type | Description |
|---|---|---|
other |
— |
Returns
Self
__mul__
1
Self
▼
Repeat string n times.
__mul__
1
Self
▼
def __mul__(self, n: SupportsIndex) -> Self
Parameters
| Name | Type | Description |
|---|---|---|
n |
— |
Returns
Self
__mod__
1
Self
▼
Format string with %-style, sanitizing non-Styled args.
__mod__
1
Self
▼
def __mod__(self, args: Any) -> Self
Parameters
| Name | Type | Description |
|---|---|---|
args |
— |
Returns
Self
__format__
1
Self
▼
Support format() built-in, preserving Styled type.
__format__
1
Self
▼
def __format__(self, format_spec: str) -> Self
Parameters
| Name | Type | Description |
|---|---|---|
format_spec |
— |
Returns
Self
Functions
ansi_sanitize
1
str
▼
Strip dangerous ANSI sequences from untrusted input.
Preserves safe SGR (styli…
ansi_sanitize
1
str
▼
def ansi_sanitize(value: Any) -> str
Strip dangerous ANSI sequences from untrusted input.
Preserves safe SGR (styling) sequences while stripping cursor movement, screen manipulation, OSC, device control, and other dangerous escapes.
This is the terminal-mode analogue ofhtml_escapefor HTML mode.
Complexity: O(n) single pass. Returns immediately if no ESC byte present.
Parameters
| Name | Type | Description |
|---|---|---|
value |
Any |
Value to sanitize (will be converted to string). |
Returns
str