xnano.components.text
xnano.components.text
¶
xnano.components.text
Display styled text, nested spans, ANSI, Markdown, or highlighted source code.
Classes:
-
Text–Display styled, marked-up, highlighted, or editable text.
Text
dataclass
¶
Text(
content: str | Text | list[str | Text] = "",
foreground: ColorLike | None = None,
background: ColorLike | None = None,
modifiers: tuple[CharacterModifier, ...] = (),
horizontal_align: Alignment | None = None,
vertical_align: VerticalAlignment | None = None,
wrap: bool = True,
input: bool = False,
placeholder: str | Text | None = None,
cursor: int | None = None,
multiline: bool = False,
rows: int | None = None,
ansi: bool = False,
markdown: bool = False,
language: str | None = None,
passthrough: Sequence[str] = (),
mask: str | None = None,
max_length: int | None = None,
read_only: bool = False,
tab_size: int = 4,
focusable: bool = False,
fill: bool = False,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Component
Display styled, marked-up, highlighted, or editable text.
Nest Text values for independently styled spans. Enable ANSI,
Markdown, or syntax highlighting for formatted content, or set input
to make a leaf editable.
Example
Text(content="Ready", color="green", modifiers=("bold",))
Attributes:
-
content(str | Text | list[str | Text]) –Plain string, nested
Text, or list of either. -
foreground(ColorLike | None) –Foreground color (deprecated alias:
color). -
background(ColorLike | None) –Background color.
-
modifiers(tuple[CharacterModifier, ...]) –Character modifiers such as bold or underline.
-
horizontal_align(Alignment | None) –Horizontal alignment at the paragraph level.
-
vertical_align(VerticalAlignment | None) –Vertical alignment within the painted area.
-
wrap(bool) –Whether long lines may wrap.
-
input(bool) –When
Trueon a leaf, participates in field focus. -
placeholder(str | Text | None) –Shown when input is empty and unfocused.
-
cursor(int | None) –Caret index for single-line input;
Nonemeans end. -
multiline(bool) –Use
CoreTextEditorwhen combined withinput. -
rows(int | None) –Preferred visible height for multiline input.
-
ansi(bool) –Parse ANSI SGR sequences in leaf content.
-
markdown(bool) –Parse markdown in leaf content.
-
language(str | None) –Pygments lexer name for syntax highlighting.
-
passthrough(Sequence[str]) –Key bindings never captured while focused.
-
mask(str | None) –Single-character display mask (password style).
-
max_length(int | None) –Optional clamp on the plain-string value.
-
read_only(bool) –Reject edits while remaining focusable.
-
tab_size(int) –Tab width for multiline tab expansion.
-
focusable(bool) –Whether this component takes field focus.
-
fill(bool) –Whether
backgroundfills the whole slot, not only glyphs.
Methods:
-
component_post_init–Validate modes and initialize the native editor when needed.
-
after_render–Record the multi-line editor caret so the terminal cursor tracks it.
-
handle_paste–Insert pasted text at the caret of a multi-line editor.
-
compose–Compose interface-neutral content for this Text.
-
handle_keyboard–Edit this text when it has focus.
-
get_terminal_node–Return composed content for terminal compatibility.
-
get_frame–Optional frame/panel chrome around composed content.
-
get_size–Return the preferred cell size of this component.
-
before_render–Called before rendering; returns the effective render area.
-
compose_extra_small–Compose content when the viewport is extra small (< 40 cols).
-
compose_small–Compose content when the viewport is small (40–79 cols).
-
compose_medium–Compose content when the viewport is medium (80–119 cols).
-
compose_large–Compose content when the viewport is large (120–159 cols).
-
compose_extra_large–Compose content when the viewport is extra large (>= 160 cols).
content
class-attribute
instance-attribute
¶
Plain string, nested Text, or a list of either.
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = None
Foreground color (deprecated alias: color).
background
class-attribute
instance-attribute
¶
background: ColorLike | None = None
Background color.
modifiers
class-attribute
instance-attribute
¶
modifiers: tuple[CharacterModifier, ...] = ()
Character modifiers such as bold or underline.
horizontal_align
class-attribute
instance-attribute
¶
horizontal_align: Alignment | None = None
Horizontal alignment at the paragraph level.
vertical_align
class-attribute
instance-attribute
¶
vertical_align: VerticalAlignment | None = None
Vertical alignment within the painted area.
input
class-attribute
instance-attribute
¶
input: bool = False
When True on a leaf, the component is an editable field.
placeholder
class-attribute
instance-attribute
¶
Shown when input is empty and unfocused.
cursor
class-attribute
instance-attribute
¶
cursor: int | None = None
Caret index for single-line input; None means end of string.
multiline
class-attribute
instance-attribute
¶
multiline: bool = False
When True with input, editing uses CoreTextEditor.
rows
class-attribute
instance-attribute
¶
rows: int | None = None
Preferred visible height (lines) for a multiline input.
ansi
class-attribute
instance-attribute
¶
ansi: bool = False
Parse ANSI SGR sequences in leaf content.
markdown
class-attribute
instance-attribute
¶
markdown: bool = False
Parse leaf content as markdown.
language
class-attribute
instance-attribute
¶
language: str | None = None
Pygments lexer name for syntax highlighting only.
passthrough
class-attribute
instance-attribute
¶
Key bindings this input never captures while focused.
mask
class-attribute
instance-attribute
¶
mask: str | None = None
Display-only mask character(s); real value is preserved.
max_length
class-attribute
instance-attribute
¶
max_length: int | None = None
Maximum plain-string length; longer input is clamped.
read_only
class-attribute
instance-attribute
¶
read_only: bool = False
Reject edits while remaining focusable.
tab_size
class-attribute
instance-attribute
¶
tab_size: int = 4
Tab width applied to multiline tab insertion and paste.
focusable
class-attribute
instance-attribute
¶
focusable: bool = False
Whether this component participates in field focus.
fill
class-attribute
instance-attribute
¶
fill: bool = False
Whether background fills the whole slot rather than only the
text glyphs. When True short lines still paint the background across
the full cell width (no manual right-padding required).
owns_cursor
property
¶
owns_cursor: bool
Whether this Text paints its own caret (multi-line editor).
cursor_position
property
¶
Absolute caret cell for the terminal cursor, set during paint.
Reported only for a focused multi-line editor (a single-line input
paints its own ▌ caret inline). None otherwise, which hides
the hardware cursor.
visible
class-attribute
instance-attribute
¶
visible: bool = dataclasses.field(
default=True, kw_only=True
)
Whether this component paints at all.
z
class-attribute
instance-attribute
¶
z: int = dataclasses.field(default=0, kw_only=True)
Stacking order among sibling content.
fit_content
class-attribute
instance-attribute
¶
fit_content: bool = dataclasses.field(
default=True, kw_only=True
)
When True, paint at natural size inside a larger slot.
component_post_init
¶
Validate modes and initialize the native editor when needed.
after_render
¶
Record the multi-line editor caret so the terminal cursor tracks it.
Source code in xnano/components/text.py
handle_paste
¶
Insert pasted text at the caret of a multi-line editor.
Parameters:
-
text(str) –The pasted clipboard text.
Returns:
-
bool–Truewhen the paste was consumed by the native editor.
Source code in xnano/components/text.py
compose
¶
compose(
ctx: ComponentRenderContext[Any],
) -> TextBlock | Native | Panel | None
Compose interface-neutral content for this Text.
Parameters:
-
ctx(ComponentRenderContext[Any]) –Render-time scope for this paint.
Returns:
-
TextBlock | Native | Panel | None–A
TextBlock,Nativeeditor payload, or nested content. -
TextBlock | Native | Panel | None–When
fillis set the block is wrapped in a background -
TextBlock | Native | Panel | None–Panelso the color spans the full slot.
Source code in xnano/components/text.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
Edit this text when it has focus.
Passthrough bindings remain available to hooks. Read-only inputs reject
edits, and max_length limits inserted content.
Parameters:
-
keyboard('KeyboardEventData') –The keyboard event payload.
Returns:
-
bool–Truewhen the key was consumed as text editing.
Source code in xnano/components/text.py
get_terminal_node
¶
get_terminal_node(
ctx: ComponentRenderContext[Any],
) -> TextBlock | Native | Panel | None
Return composed content for terminal compatibility.
Parameters:
-
ctx(ComponentRenderContext[Any]) –Render-time scope for this paint.
Returns:
Source code in xnano/components/text.py
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
compose_extra_small
¶
compose_extra_small(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:compose. When
overridden, it is used instead of compose while the window
is in this size tier. Overriding any compose_* variant opts the
component into breakpoint dispatch; a component that overrides none
pays no per-frame cost.
Source code in xnano/components/component.py
compose_small
¶
compose_small(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is small (40–79 cols).
See :meth:compose_extra_small.
compose_medium
¶
compose_medium(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is medium (80–119 cols).
See :meth:compose_extra_small.
compose_large
¶
compose_large(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is large (120–159 cols).
See :meth:compose_extra_small.
compose_extra_large
¶
compose_extra_large(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose content when the viewport is extra large (>= 160 cols).
See :meth:compose_extra_small.