textual.content
Content is a container for text, with spans marked up with color / style. It is equivalent to Rich's Text object, with support for more of Textual features.
Unlike Rich Text, Content is immutable so you can't modify it in place, and most methods will return a new Content instance. This is more like the builtin str, and allows Textual to make some significant optimizations.
ANSI_DEFAULT
module-attribute
¶
ANSI_DEFAULT = Style(
background=Color(0, 0, 0, 0, ansi=-1),
foreground=Color(0, 0, 0, 0, ansi=-1),
)
A Style for ansi default background and foreground.
ContentText
module-attribute
¶
A type that may be used to construct Text.
ContentType
module-attribute
¶
Type alias used where content and a str are interchangeable in a function.
Content
¶
Content(text='', spans=None, cell_length=None)
Bases: Visual
Text content with marked up spans.
This object can be considered immutable, although it might update its internal state in a way that is consistent with immutability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
text content. |
''
|
|
list[Span] | None
|
Optional list of spans. |
None
|
|
int | None
|
Cell length of text if known, otherwise |
None
|
markup
cached
property
¶
Get content markup to render this Text.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string potentially creating markup tags. |
spans
property
¶
A sequence of spans used to markup regions of the content.
Warning
Never attempt to mutate the spans, as this would certainly break the output--possibly in quite subtle ways!
append_text
¶
assemble
classmethod
¶
Construct new content from string, content, or tuples of (TEXT, STYLE).
This is an efficient way of constructing Content composed of smaller pieces of text and / or other Content objects.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Content | tuple[str, str | Style]
|
Parts to join to gether. A part may be a simple string, another Content |
()
|
|