xnano.components
xnano.components
¶
xnano.components
Components for text, input, data display, navigation, and feedback.
Modules:
-
bar–xnano.components.bar
-
button–xnano.components.button
-
chart–xnano.components.chart
-
component–xnano.components.component
-
dropdown–xnano.components.dropdown
-
image–xnano.components.image
-
input–xnano.components.input
-
link–xnano.components.link
-
loader–xnano.components.loader
-
markdown–xnano.components.markdown
-
options–xnano.components.options
-
schema–xnano.components.schema
-
scrollbar–xnano.components.scrollbar
-
table–xnano.components.table
-
text–xnano.components.text
Classes:
-
Bar–Compact inline bar chart for a sequence of samples.
-
Button–Focusable styled text button.
-
Chart–Declarative multi-series chart.
-
Series–Describe one chart series.
-
Bars–Render grouped bars.
-
Canvas–Render geometric shapes in numeric coordinate space.
-
CellCanvas–A rectangular sequence of styled cell rows.
-
Clear–Clear the assigned render area.
-
Component–Base class for custom xnano components.
-
ComponentRenderContext–Render-time scope passed into component paint hooks.
-
Gauge–Render a filled progress gauge.
-
Items–Render a selectable list of text items.
-
LineGauge–Render progress as a single horizontal line.
-
Panel–Decorate child content with a frame and padding.
-
Plot–Render one or more numeric data series.
-
Run–One styled text run.
-
ScrollbarContent–Render scroll position and viewport proportion.
-
Sparkline–Render a compact sequence of vertical samples.
-
Stack–Lay out child content in one direction.
-
TableGrid–Render tabular rows with optional selection.
-
TextBlock–Wrapped plain text or lines of styled runs.
-
Dropdown–Collapsible choice list.
-
Image–A native-resolution terminal image or real-time GIF component.
-
ImageData–Decoded image frames independent of Pillow and the render engine.
-
ImageFrame–One native-resolution RGB frame and its display duration.
-
Input–Editable text field.
-
Link–Focusable hyperlink label.
-
Loader–Determinate progress indicator or indeterminate spinner.
-
Markdown–Display Markdown with terminal-friendly styling.
-
Option–A labeled choice with optional distinct value and disabled flag.
-
Options–Always-visible, selectable choice list.
-
Scrollbar–Display the visible range of scrollable content.
-
Column–Describe one table column.
-
Table–Declarative data table.
-
Text–Display styled, marked-up, highlighted, or editable text.
Attributes:
-
BarDirection(TypeAlias) –Whether bar samples grow upward or downward.
-
BarGlyphPreset(TypeAlias) –Named glyph ladders for compact bar rendering.
-
BarGlyphs(TypeAlias) –Explicit ordered symbols or a named preset.
-
Content(TypeAlias) –Any content primitive.
-
ImageFit(TypeAlias) –How source pixels are placed inside the available terminal area.
-
ImageSource(TypeAlias) –A filesystem path, encoded image bytes, stream, or decoded image data.
-
LoaderStyle(TypeAlias) –Visual style for a
Loadercomponent.
BarDirection
module-attribute
¶
Whether bar samples grow upward or downward.
BarGlyphPreset
module-attribute
¶
Named glyph ladders for compact bar rendering.
BarGlyphs
module-attribute
¶
BarGlyphs: TypeAlias = str | Sequence[str] | BarGlyphPreset
Explicit ordered symbols or a named preset.
Content
module-attribute
¶
Content: TypeAlias = (
Run
| TextBlock
| Stack
| Panel
| Gauge
| LineGauge
| Bars
| Plot
| Sparkline
| TableGrid
| Items
| Canvas
| Scrollbar
| Clear
| CellCanvas
| Native
)
Any content primitive.
ImageFit
module-attribute
¶
How source pixels are placed inside the available terminal area.
ImageSource
module-attribute
¶
A filesystem path, encoded image bytes, stream, or decoded image data.
LoaderStyle
module-attribute
¶
Visual style for a Loader component.
Bar
dataclass
¶
Bar(
data: Sequence[int | float] = tuple(),
foreground: "ColorLike | None" = None,
colors: Sequence["ColorLike"] | None = None,
background: "ColorLike | None" = None,
max_value: int | float | None = None,
direction: BarDirection = "up",
glyphs: BarGlyphs = "blocks",
absent_color: "ColorLike | None" = None,
absent_glyph: str | None = None,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = False
)
Bases: Component
Compact inline bar chart for a sequence of samples.
Fills its layout slot by default and scales sample heights across the
available vertical area when using the native sparkline path. Supply
colors with one entry per sample to tint individual bars.
Example
Bar(data=(2, 5, 3, 8), color="cyan")
Attributes:
-
data(Sequence[int | float]) –Sequence of sample values.
-
foreground('ColorLike | None') –Default bar foreground color (deprecated alias:
color). -
colors(Sequence['ColorLike'] | None) –Optional per-bar foreground colors.
-
background('ColorLike | None') –Widget background color.
-
max_value(int | float | None) –Explicit y-axis ceiling;
Noneauto-scales. -
direction(BarDirection) –Whether samples grow
"up"or"down". -
glyphs(BarGlyphs) –Ordered fill ladder or a named preset.
-
absent_color('ColorLike | None') –Color applied to zero or absent samples.
-
absent_glyph(str | None) –Glyph drawn for absent samples.
Methods:
-
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.
-
after_render–Called after rendering for optional post-paint work.
-
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).
-
handle_keyboard–Optional keyboard handler while focused.
-
handle_paste–Optional paste handler while focused.
-
component_post_init–Resolve and validate the glyph ladder once.
-
compose–Compose sparkline content, with a native/canvas paint path.
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.
data
class-attribute
instance-attribute
¶
Sequence of sample values.
foreground
class-attribute
instance-attribute
¶
Default bar foreground color (deprecated alias: color).
colors
class-attribute
instance-attribute
¶
colors: Sequence['ColorLike'] | None = None
Optional per-bar foreground colors, one per data entry.
background
class-attribute
instance-attribute
¶
Widget background color.
max_value
class-attribute
instance-attribute
¶
Explicit y-axis ceiling; None auto-scales to the dataset max.
direction
class-attribute
instance-attribute
¶
direction: BarDirection = 'up'
Whether samples grow "up" or "down".
glyphs
class-attribute
instance-attribute
¶
glyphs: BarGlyphs = 'blocks'
Ordered fill ladder or a named preset (blocks/braille/ascii).
absent_color
class-attribute
instance-attribute
¶
Color applied to zero or absent samples.
absent_glyph
class-attribute
instance-attribute
¶
absent_glyph: str | None = None
Glyph drawn for absent samples.
fit_content
class-attribute
instance-attribute
¶
fit_content: bool = dataclasses.field(
default=False, kw_only=True
)
Whether layout should use the sparkline's natural width.
resolved_glyphs
property
¶
Resolved ordered glyph ladder used for rendering.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
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.
Source code in xnano/components/component.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
handle_paste
¶
component_post_init
¶
Resolve and validate the glyph ladder once.
Source code in xnano/components/bar.py
compose
¶
Compose sparkline content, with a native/canvas paint path.
Returns:
-
–
Interface-neutral content for this bar.
Source code in xnano/components/bar.py
Button
dataclass
¶
Button(
label: str | Any = "",
disabled: bool = False,
focusable: bool = True,
foreground: ColorLike | None = None,
background: ColorLike | None = None,
focused_color: ColorLike | None = "black",
focused_background: ColorLike | None = "white",
disabled_color: ColorLike | None = "gray",
disabled_background: ColorLike | None = None,
left: str = "[ ",
right: str = " ]",
activation_keys: Sequence[str] = ("enter", "space"),
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Component
Focusable styled text button.
Buttons use the same hooks as every other field. Assign a group and handle clicks or activation keys on the grid:
class Form(BaseGrid):
submit: Button = Field(
default=Button("Submit"),
group="submit",
)
@on_click(group="submit")
@on_keyboard("enter", group="submit")
def submit_form(self, ctx: Context) -> None: ...
Example
Button(label="Save", focused_background="blue")
Attributes:
-
label(str | Any) –Button caption (plain string or styled
Text). -
disabled(bool) –When
True, paints disabled colors and ignores activation. -
focusable(bool) –Whether this button participates in field focus.
-
foreground(ColorLike | None) –Idle foreground color (deprecated alias:
color). -
background(ColorLike | None) –Idle background color.
-
focused_color(ColorLike | None) –Foreground while focused.
-
focused_background(ColorLike | None) –Background while focused.
-
disabled_color(ColorLike | None) –Foreground while disabled.
-
disabled_background(ColorLike | None) –Background while disabled.
-
left(str) –Prefix chrome around the label.
-
right(str) –Suffix chrome around the label.
-
activation_keys(Sequence[str]) –Bindings that should bubble to hooks (never consumed by the button itself).
Methods:
-
component_post_init–Initialize subclass state after dataclass fields are assigned.
-
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.
-
after_render–Called after rendering for optional post-paint work.
-
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).
-
handle_paste–Optional paste handler while focused.
-
get_label_text–Return the plain-text form of
label. -
handle_keyboard–Leave keyboard activation to the grid's event hooks.
-
compose–Compose a styled label, wrapped in a panel when focused.
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.
label
class-attribute
instance-attribute
¶
Button caption (plain string or styled Text).
disabled
class-attribute
instance-attribute
¶
disabled: bool = False
When True, paints disabled colors and ignores activation.
focusable
class-attribute
instance-attribute
¶
focusable: bool = True
Whether this button participates in field focus (tab order).
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = None
Idle foreground color (deprecated alias: color).
background
class-attribute
instance-attribute
¶
background: ColorLike | None = None
Idle background color.
focused_color
class-attribute
instance-attribute
¶
focused_color: ColorLike | None = 'black'
Foreground while focused.
focused_background
class-attribute
instance-attribute
¶
focused_background: ColorLike | None = 'white'
Background while focused.
disabled_color
class-attribute
instance-attribute
¶
disabled_color: ColorLike | None = 'gray'
Foreground while disabled.
disabled_background
class-attribute
instance-attribute
¶
disabled_background: ColorLike | None = None
Background while disabled.
activation_keys
class-attribute
instance-attribute
¶
Bindings that bubble to hooks (never consumed here).
component_post_init
¶
Initialize subclass state after dataclass fields are assigned.
Override this method instead of __post_init__.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
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.
Source code in xnano/components/component.py
handle_paste
¶
get_label_text
¶
get_label_text() -> str
Return the plain-text form of label.
Source code in xnano/components/button.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
Leave keyboard activation to the grid's event hooks.
Parameters:
-
keyboard('KeyboardEventData') –The keyboard event payload.
Returns:
-
bool–Falseso the event continues to hooks.
Source code in xnano/components/button.py
compose
¶
compose(ctx: 'ComponentRenderContext') -> Any
Compose a styled label, wrapped in a panel when focused.
Parameters:
-
ctx('ComponentRenderContext') –Render-time scope for this paint.
Returns:
Source code in xnano/components/button.py
Chart
dataclass
¶
Chart(
series: dict[str, SeriesData] = dict(),
kind: GraphTypeLike = "line",
colors: Sequence["ColorLike"] | None = None,
x_bounds: tuple[float, float] | None = None,
y_bounds: tuple[float, float] | None = None,
x_label: str | None = None,
y_label: str | None = None,
x_labels: Sequence[str] | None = None,
y_labels: Sequence[str] | None = None,
legend: bool = True,
legend_position: LegendPositionLike = "top_right",
marker: CanvasMarkerLike | None = None,
hidden_series: Sequence[str] = (),
*,
visible: bool = True,
z: int = 0,
fit_content: bool = False
)
Bases: Component
Declarative multi-series chart.
Hand it a mapping of series name → points and it derives the datasets,
legend, axis bounds, and a cycled color per series. Points may be
(x, y) pairs or bare y values (the x-axis becomes the index).
Example
Chart(series={"requests": (3, 5, 4, 8)})
Attributes:
-
series(dict[str, SeriesData]) –Mapping of series name → points.
-
kind(GraphTypeLike) –Default plot kind for series that do not override it.
-
colors(Sequence['ColorLike'] | None) –Palette cycled across series.
-
x_bounds(tuple[float, float] | None) –Explicit x-axis
(min, max). -
y_bounds(tuple[float, float] | None) –Explicit y-axis
(min, max). -
x_label(str | None) –Optional x-axis title.
-
y_label(str | None) –Optional y-axis title.
-
x_labels(Sequence[str] | None) –Optional x-axis tick labels.
-
y_labels(Sequence[str] | None) –Optional y-axis tick labels.
-
legend(bool) –Whether to show the legend.
-
legend_position(LegendPositionLike) –Legend placement when enabled.
-
marker(CanvasMarkerLike | None) –Default marker glyph set for series.
-
hidden_series(Sequence[str]) –Series names omitted from paint.
Methods:
-
component_post_init–Initialize subclass state after dataclass fields are assigned.
-
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.
-
after_render–Called after rendering for optional post-paint work.
-
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).
-
handle_keyboard–Optional keyboard handler while focused.
-
handle_paste–Optional paste handler while focused.
-
compose–Compose Plot content with a native ChartNode paint fallback.
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.
series
class-attribute
instance-attribute
¶
series: dict[str, SeriesData] = dataclasses.field(
default_factory=dict
)
Mapping of series name → points.
kind
class-attribute
instance-attribute
¶
kind: GraphTypeLike = 'line'
Default plot kind for series that do not override it.
colors
class-attribute
instance-attribute
¶
colors: Sequence['ColorLike'] | None = None
Palette cycled across series; None uses a built-in palette.
x_bounds
class-attribute
instance-attribute
¶
x-axis (min, max); None auto-fits to the data.
y_bounds
class-attribute
instance-attribute
¶
y-axis (min, max); None auto-fits to the data.
x_labels
class-attribute
instance-attribute
¶
Optional x-axis tick labels.
y_labels
class-attribute
instance-attribute
¶
Optional y-axis tick labels.
legend
class-attribute
instance-attribute
¶
legend: bool = True
Whether to show the legend (labelled from series names).
legend_position
class-attribute
instance-attribute
¶
legend_position: LegendPositionLike = 'top_right'
Legend placement when legend is enabled.
marker
class-attribute
instance-attribute
¶
marker: CanvasMarkerLike | None = None
Default marker glyph set for series that do not override it.
hidden_series
class-attribute
instance-attribute
¶
Series names omitted from paint and bounds.
fit_content
class-attribute
instance-attribute
¶
fit_content: bool = dataclasses.field(
default=False, kw_only=True
)
Whether layout should use the plot's natural size.
datasets
property
¶
datasets: tuple[ResolvedDataset, ...]
Read-only resolved view of plotted datasets.
component_post_init
¶
Initialize subclass state after dataclass fields are assigned.
Override this method instead of __post_init__.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
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.
Source code in xnano/components/component.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
handle_paste
¶
compose
¶
Compose Plot content with a native ChartNode paint fallback.
Returns:
-
–
Interface-neutral content for this chart.
Series
dataclass
¶
Series(
label: str | None = None,
color: "ColorLike | None" = None,
kind: "GraphTypeLike | None" = None,
marker: "CanvasMarkerLike | None" = None,
)
Bases: ComponentDescriptor
Describe one chart series.
Attributes:
-
label(str | None) –Legend label;
Nonederives it from the attribute name. -
color('ColorLike | None') –Series color.
-
kind('GraphTypeLike | None') –Plot representation.
-
marker('CanvasMarkerLike | None') –Glyph set used to paint the series.
Methods:
-
resolve_label–Return the displayed legend label.
name
class-attribute
instance-attribute
¶
name: str = dataclasses.field(default='', init=False)
Attribute name assigned by the component class.
marker
class-attribute
instance-attribute
¶
Marker used to paint samples.
Bars
dataclass
¶
Bars(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
groups: tuple[BarGroup, ...] = (),
bar_width: int = 1,
bar_gap: int = 1,
group_gap: int = 0,
max_value: int | None = None,
direction: Direction = "vertical",
color: ColorLike | None = None,
value_color: ColorLike | None = None,
label_color: ColorLike | None = None
)
Bases: ContentBase
Render grouped bars.
Example
Bars(groups=(BarGroup(bars=(Bar(value=8, label="A"),)),))
Attributes:
-
groups(tuple[BarGroup, ...]) –Bar groups.
-
bar_width(int) –Width of each bar in cells.
-
bar_gap(int) –Cells between bars.
-
group_gap(int) –Cells between groups.
-
max_value(int | None) –Explicit value ceiling.
-
direction(Direction) –Bar growth direction.
-
color(ColorLike | None) –Default bar color.
-
value_color(ColorLike | None) –Default value-label color.
-
label_color(ColorLike | None) –Bar-label color.
Canvas
dataclass
¶
Canvas(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
shapes: tuple[CanvasShape, ...] = (),
x_bounds: tuple[float, float] = (0.0, 1.0),
y_bounds: tuple[float, float] = (0.0, 1.0),
marker: CanvasMarkerLike = "braille",
background: ColorLike | None = None
)
Bases: ContentBase
Render geometric shapes in numeric coordinate space.
Example
Canvas(shapes=(CanvasCircle(x=0.5, y=0.5, radius=0.25),))
Attributes:
-
shapes(tuple[CanvasShape, ...]) –Shapes painted in declaration order.
-
x_bounds(tuple[float, float]) –Horizontal coordinate bounds.
-
y_bounds(tuple[float, float]) –Vertical coordinate bounds.
-
marker(CanvasMarkerLike) –Canvas point marker.
-
background(ColorLike | None) –Canvas background.
shapes
class-attribute
instance-attribute
¶
shapes: tuple[CanvasShape, ...] = ()
Shapes painted in declaration order.
x_bounds
class-attribute
instance-attribute
¶
Horizontal coordinate bounds.
y_bounds
class-attribute
instance-attribute
¶
Vertical coordinate bounds.
marker
class-attribute
instance-attribute
¶
marker: CanvasMarkerLike = 'braille'
Canvas point marker.
CellCanvas
dataclass
¶
CellCanvas(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
rows: tuple[tuple[CellSpan, ...], ...] = (),
width: int = 0,
height: int = 0
)
Bases: ContentBase
A rectangular sequence of styled cell rows.
Example
CellCanvas.from_rows(((CellSpan("OK", color="green"),),))
Attributes:
-
rows(tuple[tuple[CellSpan, ...], ...]) –Rows of styled spans.
-
width(int) –Canvas width in cells.
-
height(int) –Canvas height in cells.
Methods:
-
from_rows–Create a cell canvas from styled span rows.
rows
class-attribute
instance-attribute
¶
Rows of styled spans.
from_rows
classmethod
¶
from_rows(
rows: Sequence[Sequence[CellSpan | str]],
*,
width: int | None = None,
style: Style | None = None,
z: int = 0,
visible: bool = True
) -> "CellCanvas"
Create a cell canvas from styled span rows.
Source code in xnano/core/content.py
Clear
dataclass
¶
Component
dataclass
¶
Base class for custom xnano components.
Component attributes are live state: changing an attribute changes the
next rendered frame. Implement compose() to return content. Interactive
components can also implement handle_keyboard() or handle_paste().
The framework updates the read-only focused property when the
component gains or loses field focus.
Example
Text(content="Ready", color="green")
Attributes:
-
visible(bool) –Whether the component is rendered.
-
z(int) –Paint order relative to sibling components.
-
fit_content(bool) –Whether layout should prefer the natural content size.
Methods:
-
component_post_init–Initialize subclass state after dataclass fields are assigned.
-
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.
-
after_render–Called after rendering for optional post-paint work.
-
compose–Compose interface-neutral content for this component.
-
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).
-
handle_keyboard–Optional keyboard handler while focused.
-
handle_paste–Optional paste handler while focused.
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
¶
Initialize subclass state after dataclass fields are assigned.
Override this method instead of __post_init__.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
compose
¶
compose(
ctx: ComponentRenderContext[StateT],
) -> Content | None
Compose interface-neutral content for this component.
Returns:
-
Content | None–A
Contenttree, orNonewhen nothing should paint.
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.
Source code in xnano/components/component.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
ComponentRenderContext
dataclass
¶
ComponentRenderContext(
area: "Area",
terminal: "Terminal[StateT] | None" = None,
state: StateT | None = None,
component: "Component | None" = None,
)
Bases: Generic[StateT]
Render-time scope passed into component paint hooks.
Attributes:
-
area('Area') –Target area for this paint.
-
terminal('Terminal[StateT] | None') –Terminal handling the render, when available.
-
state(StateT | None) –Application state for this paint.
-
component('Component | None') –Component being rendered, when known.
Gauge
dataclass
¶
Gauge(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
progress: float = 0.0,
label: str | None = None,
foreground: ColorLike = "green",
background: ColorLike | None = None
)
Bases: ContentBase
Render a filled progress gauge.
Example
Gauge(progress=0.75, label="75%")
Attributes:
-
progress(float) –Completion ratio from zero to one.
-
label(str | None) –Text displayed inside the gauge.
-
foreground(ColorLike) –Filled-region color.
-
background(ColorLike | None) –Gauge background color.
progress
class-attribute
instance-attribute
¶
progress: float = 0.0
Completion ratio from zero to one.
label
class-attribute
instance-attribute
¶
label: str | None = None
Text displayed inside the gauge.
Items
dataclass
¶
Items(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
items: tuple[str | Run | TextBlock, ...] = (),
selected: int | None = None,
foreground: ColorLike | None = None,
background: ColorLike | None = None,
highlight_color: ColorLike = "black",
highlight_background: ColorLike = "white",
highlight_symbol: str = "> "
)
Bases: ContentBase
Render a selectable list of text items.
Example
Items(items=("One", "Two"), selected=0)
Attributes:
-
items(tuple[str | Run | TextBlock, ...]) –List entries.
-
selected(int | None) –Selected entry index.
-
foreground(ColorLike | None) –Default foreground.
-
background(ColorLike | None) –Default background.
-
highlight_color(ColorLike) –Selected-entry foreground.
-
highlight_background(ColorLike) –Selected-entry background.
-
highlight_symbol(str) –Symbol prefixed to the selected entry.
items
class-attribute
instance-attribute
¶
List entries.
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = None
Default foreground.
background
class-attribute
instance-attribute
¶
background: ColorLike | None = None
Default background.
highlight_color
class-attribute
instance-attribute
¶
highlight_color: ColorLike = 'black'
Selected-entry foreground.
LineGauge
dataclass
¶
LineGauge(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
progress: float = 0.0,
label: str | None = None,
foreground: ColorLike | None = None,
filled_color: ColorLike | None = None,
unfilled_color: ColorLike | None = None,
background: ColorLike | None = None
)
Bases: ContentBase
Render progress as a single horizontal line.
Attributes:
-
progress(float) –Completion ratio from zero to one.
-
label(str | None) –Text displayed with the line.
-
foreground(ColorLike | None) –Default foreground color.
-
filled_color(ColorLike | None) –Completed-region color.
-
unfilled_color(ColorLike | None) –Remaining-region color.
-
background(ColorLike | None) –Line background color.
progress
class-attribute
instance-attribute
¶
progress: float = 0.0
Completion ratio from zero to one.
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = None
Default foreground color.
filled_color
class-attribute
instance-attribute
¶
filled_color: ColorLike | None = None
Completed-region color.
Panel
dataclass
¶
Panel(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
child: ContentBase,
title: str | None = None,
title_position: FrameTitlePosition | None = None,
border: Border | None = None,
border_color: ColorLike | None = None,
border_sides: tuple[Side, ...] | None = None,
background: ColorLike | None = None,
padding: PaddingLike | None = None
)
Bases: ContentBase
Decorate child content with a frame and padding.
Example
Panel(child=TextBlock(text="Status"), title="Service")
Attributes:
-
child(ContentBase) –Content inside the panel.
-
title(str | None) –Optional frame title.
-
title_position(FrameTitlePosition | None) –Frame title alignment.
-
border(Border | None) –Border style.
-
border_color(ColorLike | None) –Border foreground color.
-
border_sides(tuple[Side, ...] | None) –Visible border sides.
-
background(ColorLike | None) –Panel background color.
-
padding(PaddingLike | None) –Space between border and child.
title_position
class-attribute
instance-attribute
¶
title_position: FrameTitlePosition | None = None
Frame title alignment.
border_color
class-attribute
instance-attribute
¶
border_color: ColorLike | None = None
Border foreground color.
border_sides
class-attribute
instance-attribute
¶
Visible border sides.
background
class-attribute
instance-attribute
¶
background: ColorLike | None = None
Panel background color.
padding
class-attribute
instance-attribute
¶
padding: PaddingLike | None = None
Space between border and child.
Plot
dataclass
¶
Plot(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
datasets: tuple[PlotDataset, ...] = (),
x_axis: PlotAxis | None = None,
y_axis: PlotAxis | None = None,
color: ColorLike | None = None,
legend: bool = True,
legend_position: LegendPositionLike | None = "top_right"
)
Bases: ContentBase
Render one or more numeric data series.
Example
Plot(datasets=(PlotDataset(data=((0, 1), (1, 3))),))
Attributes:
-
datasets(tuple[PlotDataset, ...]) –Data series.
-
x_axis(PlotAxis | None) –Horizontal axis.
-
y_axis(PlotAxis | None) –Vertical axis.
-
color(ColorLike | None) –Default plot color.
-
legend(bool) –Whether to show the legend.
-
legend_position(LegendPositionLike | None) –Legend placement.
legend_position
class-attribute
instance-attribute
¶
legend_position: LegendPositionLike | None = 'top_right'
Legend placement.
Run
dataclass
¶
Run(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
text: str,
foreground: ColorLike | None = None,
background: ColorLike | None = None,
modifiers: tuple[CharacterModifier, ...] = (),
color: InitVar[Any] = _ALIAS_UNSET
)
Bases: ContentBase
One styled text run.
Example
Run(text="Ready", foreground="green", modifiers=("bold",))
Attributes:
-
text(str) –Text displayed by the run.
-
foreground(ColorLike | None) –Foreground color.
-
background(ColorLike | None) –Background color.
-
modifiers(tuple[CharacterModifier, ...]) –Character modifiers.
Methods:
-
__post_init__–Apply the deprecated constructor alias.
-
plain–Create a plain styled run.
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = None
Foreground color.
background
class-attribute
instance-attribute
¶
background: ColorLike | None = None
Background color.
modifiers
class-attribute
instance-attribute
¶
modifiers: tuple[CharacterModifier, ...] = ()
Character modifiers.
plain
classmethod
¶
plain(
text: str,
*,
foreground: ColorLike | None = None,
background: ColorLike | None = None,
modifiers: Sequence[CharacterModifier] | None = None,
style: Style | None = None,
z: int = 0,
visible: bool = True,
color: ColorLike | None = None
) -> "Run"
Create a plain styled run.
Parameters:
-
text(str) –Text displayed by the run.
-
foreground(ColorLike | None, default:None) –Foreground color.
-
background(ColorLike | None, default:None) –Background color.
-
modifiers(Sequence[CharacterModifier] | None, default:None) –Character modifiers.
-
style(Style | None, default:None) –Optional shared style.
-
z(int, default:0) –Sibling-local paint order.
-
visible(bool, default:True) –Whether the run paints.
-
color(ColorLike | None, default:None) –Deprecated alias for
foreground.
Returns:
-
'Run'–A run containing
text.
Source code in xnano/core/content.py
ScrollbarContent
dataclass
¶
ScrollbarContent(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
content_length: int = 0,
position: int = 0,
viewport_length: int = 0,
orientation: ScrollbarOrientationLike = "vertical_right",
thumb_symbol: str | None = None,
track_symbol: str | None = None,
begin_symbol: str | None = None,
end_symbol: str | None = None,
color: ColorLike | None = None,
thumb_color: ColorLike | None = None,
track_color: ColorLike | None = None
)
Bases: ContentBase
Render scroll position and viewport proportion.
Example
Scrollbar(content_length=100, viewport_length=20, position=10)
Attributes:
-
content_length(int) –Total scrollable length.
-
position(int) –Current scroll offset.
-
viewport_length(int) –Visible length.
-
orientation(ScrollbarOrientationLike) –Scrollbar edge and direction.
-
thumb_symbol(str | None) –Custom thumb symbol.
-
track_symbol(str | None) –Custom track symbol.
-
begin_symbol(str | None) –Symbol at the beginning.
-
end_symbol(str | None) –Symbol at the end.
-
color(ColorLike | None) –Default scrollbar color.
-
thumb_color(ColorLike | None) –Thumb color.
-
track_color(ColorLike | None) –Track color.
content_length
class-attribute
instance-attribute
¶
content_length: int = 0
Total scrollable length.
orientation
class-attribute
instance-attribute
¶
orientation: ScrollbarOrientationLike = 'vertical_right'
Scrollbar edge and direction.
thumb_symbol
class-attribute
instance-attribute
¶
thumb_symbol: str | None = None
Custom thumb symbol.
track_symbol
class-attribute
instance-attribute
¶
track_symbol: str | None = None
Custom track symbol.
Sparkline
dataclass
¶
Sparkline(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
data: tuple[int, ...] = (),
bars: tuple[SparklineBar, ...] | None = None,
max_value: int | None = None,
foreground: ColorLike | None = None,
background: ColorLike | None = None,
absent_value_color: ColorLike | None = None,
absent_value_symbol: str | None = None
)
Bases: ContentBase
Render a compact sequence of vertical samples.
Example
Sparkline(data=(2, 5, 3, 8), foreground="cyan")
Attributes:
-
data(tuple[int, ...]) –Sample values.
-
bars(tuple[SparklineBar, ...] | None) –Individually styled samples.
-
max_value(int | None) –Explicit sample ceiling.
-
foreground(ColorLike | None) –Default sample color.
-
background(ColorLike | None) –Sparkline background.
-
absent_value_color(ColorLike | None) –Color for missing or zero samples.
-
absent_value_symbol(str | None) –Symbol for missing or zero samples.
bars
class-attribute
instance-attribute
¶
bars: tuple[SparklineBar, ...] | None = None
Individually styled samples.
max_value
class-attribute
instance-attribute
¶
max_value: int | None = None
Explicit sample ceiling.
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = None
Default sample color.
background
class-attribute
instance-attribute
¶
background: ColorLike | None = None
Sparkline background.
Stack
dataclass
¶
Stack(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
children: tuple[ContentBase, ...] = (),
direction: Direction = "vertical",
gap: int = 0
)
Bases: ContentBase
Lay out child content in one direction.
Example
Stack(children=(TextBlock(text="One"), TextBlock(text="Two")))
Attributes:
-
children(tuple[ContentBase, ...]) –Child content.
-
direction(Direction) –Layout direction.
-
gap(int) –Cells between children.
TableGrid
dataclass
¶
TableGrid(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
rows: tuple[TableRow, ...] = (),
header: TableRow | None = None,
footer: TableRow | None = None,
column_widths: tuple[int | float, ...] | None = None,
column_spacing: int = 1,
selected_row: int | None = None,
selected_column: int | None = None,
highlight_color: ColorLike | None = None,
highlight_background: ColorLike | None = None,
highlight_symbol: str | None = None
)
Bases: ContentBase
Render tabular rows with optional selection.
Example
TableGrid(rows=(TableRow(cells=("Ada", "Engineer")),))
Attributes:
-
rows(tuple[TableRow, ...]) –Body rows.
-
header(TableRow | None) –Optional header row.
-
footer(TableRow | None) –Optional footer row.
-
column_widths(tuple[int | float, ...] | None) –Fixed cell widths or fractional widths.
-
column_spacing(int) –Cells between columns.
-
selected_row(int | None) –Selected body row.
-
selected_column(int | None) –Selected column.
-
highlight_color(ColorLike | None) –Selection foreground.
-
highlight_background(ColorLike | None) –Selection background.
-
highlight_symbol(str | None) –Symbol prefixed to the selected row.
column_widths
class-attribute
instance-attribute
¶
Fixed cell widths or fractional widths.
selected_row
class-attribute
instance-attribute
¶
selected_row: int | None = None
Selected body row.
selected_column
class-attribute
instance-attribute
¶
selected_column: int | None = None
Selected column.
highlight_color
class-attribute
instance-attribute
¶
highlight_color: ColorLike | None = None
Selection foreground.
TextBlock
dataclass
¶
TextBlock(
*,
style: Style | None = None,
z: int = 0,
visible: bool = True,
text: str = "",
lines: tuple[tuple[Run, ...], ...] = (),
foreground: ColorLike | None = None,
background: ColorLike | None = None,
modifiers: tuple[CharacterModifier, ...] = (),
horizontal_align: Alignment | None = None,
vertical_align: VerticalAlignment | None = None,
wrap: bool = True,
color: InitVar[Any] = _ALIAS_UNSET,
align: InitVar[Any] = _ALIAS_UNSET
)
Bases: ContentBase
Wrapped plain text or lines of styled runs.
Example
TextBlock(text="Hello", horizontal_align="center")
Attributes:
-
text(str) –Plain text content.
-
lines(tuple[tuple[Run, ...], ...]) –Styled text lines.
-
foreground(ColorLike | None) –Default foreground color.
-
background(ColorLike | None) –Default background color.
-
modifiers(tuple[CharacterModifier, ...]) –Default character modifiers.
-
horizontal_align(Alignment | None) –Horizontal alignment.
-
vertical_align(VerticalAlignment | None) –Vertical alignment within the painted area.
-
wrap(bool) –Whether long lines wrap.
Methods:
-
__post_init__–Apply deprecated constructor aliases.
-
from_plain–Create a block from plain text and explicit style values.
-
from_lines–Create a block from styled line sequences.
lines
class-attribute
instance-attribute
¶
Styled text lines.
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = None
Default foreground color.
background
class-attribute
instance-attribute
¶
background: ColorLike | None = None
Default background color.
modifiers
class-attribute
instance-attribute
¶
modifiers: tuple[CharacterModifier, ...] = ()
Default character modifiers.
horizontal_align
class-attribute
instance-attribute
¶
horizontal_align: Alignment | None = None
Horizontal alignment.
vertical_align
class-attribute
instance-attribute
¶
vertical_align: VerticalAlignment | None = None
Vertical alignment within the painted area.
__post_init__
¶
Apply deprecated constructor aliases.
from_plain
classmethod
¶
from_plain(
text: str,
*,
foreground: ColorLike | None = None,
background: ColorLike | None = None,
modifiers: Sequence[CharacterModifier] | None = None,
horizontal_align: Alignment | None = None,
vertical_align: VerticalAlignment | None = None,
wrap: bool = True,
style: Style | None = None,
z: int = 0,
visible: bool = True,
color: ColorLike | None = None
) -> "TextBlock"
Create a block from plain text and explicit style values.
color is a deprecated alias for foreground.
Source code in xnano/core/content.py
from_lines
classmethod
¶
from_lines(
lines: Sequence[Sequence[Run] | Run | str],
*,
foreground: ColorLike | None = None,
background: ColorLike | None = None,
modifiers: Sequence[CharacterModifier] | None = None,
horizontal_align: Alignment | None = None,
vertical_align: VerticalAlignment | None = None,
wrap: bool = True,
style: Style | None = None,
z: int = 0,
visible: bool = True,
color: ColorLike | None = None
) -> "TextBlock"
Create a block from styled line sequences.
color is a deprecated alias for foreground.
Source code in xnano/core/content.py
Dropdown
dataclass
¶
Dropdown(
items: Sequence[OptionItem] = (),
query: str = "",
filter: FilterMode = "fuzzy",
accept: AcceptPolicy = "replace",
searchable: bool = True,
selected: int = 0,
direction: OptionsDirection = "top_to_bottom",
foreground: ColorLike | None = None,
background: ColorLike | None = None,
highlight_color: ColorLike = "black",
highlight_background: ColorLike = "white",
highlight_symbol: str = "> ",
hovered: int | None = None,
hover_symbol: str = "· ",
match_color: ColorLike | None = "cyan",
repeat_highlight_symbol: bool = False,
focusable: bool = True,
passthrough: Sequence[str] = (),
open: bool = False,
placeholder: str | Any | None = None,
max_visible: int | None = None,
close_on_select: bool = True,
open_keys: Sequence[str] = ("enter", "space", "down"),
close_keys: Sequence[str] = ("enter", "escape"),
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Options
Collapsible choice list.
When closed, the dropdown shows the selected label or placeholder. When open, users can search and move through the available options.
class Form(BaseGrid):
theme: Dropdown = Field(
default=Dropdown(
items=("dark", "light", "system"),
placeholder="pick a theme",
),
)
@on_keyboard("enter")
def _choose(self, ctx: Context) -> None:
if not self.theme.open:
apply_theme(self.theme.value)
Example
Dropdown(items=("dark", "light"), placeholder="Choose a theme")
Attributes:
-
open(bool) –Whether the options list is expanded.
-
placeholder(str | Any | None) –Closed-row text when nothing is selected.
-
max_visible(int | None) –Cap on open-list rows around the selection.
-
close_on_select(bool) –Close after enter accepts the selection.
-
open_keys(Sequence[str]) –Bindings that open a closed dropdown.
-
close_keys(Sequence[str]) –Bindings that close an open dropdown (enter also accepts the current selection first).
Methods:
-
component_post_init–Initialize subclass state after dataclass fields are assigned.
-
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.
-
after_render–Record the painted area so hover can map a pointer to a row.
-
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).
-
handle_paste–Optional paste handler while focused.
-
select_value–Select the visible item whose stored value equals
value. -
resolve_submission–Reconcile typed composer text with the selection per
accept. -
move–Move
selectedbydelta, skipping disabled entries. -
select–Set
selectedtoindexwithin the filtered view. -
clear_query–Clear the filter query and reset selection to the first row.
-
handle_hover–Mark the row under the pointer as hovered (mouse hover).
-
handle_keyboard–Open, close, search, or move through the dropdown.
-
compose–Compose closed label or open options content.
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.
items
class-attribute
instance-attribute
¶
items: Sequence[OptionItem] = ()
Entries to pick from (plain strings, Text, or Option).
query
class-attribute
instance-attribute
¶
query: str = ''
Filter text. Edited by typing while focused when searchable;
assign it from a hook to filter reactively.
filter
class-attribute
instance-attribute
¶
filter: FilterMode = 'fuzzy'
How query narrows the visible items — see FilterMode.
"fuzzy"/True fuzzy-match, "prefix" prefix-match, "none"/
False show everything (for externally filtered items), or a
(query, item_text) -> bool callable.
accept
class-attribute
instance-attribute
¶
accept: AcceptPolicy = 'replace'
How resolve_submission reconciles typed text with the selection.
selected
class-attribute
instance-attribute
¶
selected: int = 0
Selection index within the filtered view.
direction
class-attribute
instance-attribute
¶
direction: OptionsDirection = 'top_to_bottom'
Visual order of option rows in the list.
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = None
Default foreground color for unselected rows (deprecated alias:
color).
background
class-attribute
instance-attribute
¶
background: ColorLike | None = None
Default background color for unselected rows.
highlight_color
class-attribute
instance-attribute
¶
highlight_color: ColorLike = 'black'
Foreground of the selected row.
highlight_background
class-attribute
instance-attribute
¶
highlight_background: ColorLike = 'white'
Background of the selected row.
highlight_symbol
class-attribute
instance-attribute
¶
highlight_symbol: str = '> '
Symbol prepended to the selected row.
hovered
class-attribute
instance-attribute
¶
hovered: int | None = None
Row under the pointer (filtered-view index), or None.
Set by :meth:handle_hover when mouse events are enabled; drawn as a
dim hover_symbol so it reads as distinct from the selection.
hover_symbol
class-attribute
instance-attribute
¶
hover_symbol: str = '· '
Symbol prepended to the hovered row (dim), distinct from selection.
match_color
class-attribute
instance-attribute
¶
match_color: ColorLike | None = 'cyan'
Emphasis color for characters matched by query.
repeat_highlight_symbol
class-attribute
instance-attribute
¶
repeat_highlight_symbol: bool = False
When True, every row shows the highlight symbol.
focusable
class-attribute
instance-attribute
¶
focusable: bool = True
Whether this Options participates in field focus (tab order).
passthrough
class-attribute
instance-attribute
¶
Key bindings this list never captures while focused.
owns_cursor
class-attribute
instance-attribute
¶
owns_cursor: bool = dataclasses.field(
default=True, init=False
)
Whether selection replaces the hardware caret.
filtered
property
¶
Indices into items currently visible, in display order.
Use this with visible_items to inspect the current filtered view.
visible_items
property
¶
Plain text of the currently visible items, in display order.
selected_item
property
¶
selected_item: OptionItem | None
The selected item object, or None when the view is empty.
selected_value
property
¶
selected_value: Any | None
Stable stored value of the selection (alias of value).
Use with select_value to preserve a selection across item
rebuilds by value/id rather than by fragile filtered index.
selected_label
property
¶
selected_label: str
Plain display text of the selected item, or "" when empty.
searchable
class-attribute
instance-attribute
¶
searchable: bool = True
Whether typing while open edits query.
A dropdown is a search box when expanded, so unlike a plain Options
list it defaults to True; set False for a pick-only dropdown.
placeholder
class-attribute
instance-attribute
¶
Closed-row text when nothing is selected (string or Text).
max_visible
class-attribute
instance-attribute
¶
max_visible: int | None = None
Cap on open-list rows around the selection; None shows all.
close_on_select
class-attribute
instance-attribute
¶
close_on_select: bool = True
Close after enter accepts the current selection.
open_keys
class-attribute
instance-attribute
¶
Bindings that open a closed dropdown.
close_keys
class-attribute
instance-attribute
¶
Bindings that close an open dropdown.
component_post_init
¶
Initialize subclass state after dataclass fields are assigned.
Override this method instead of __post_init__.
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.
Source code in xnano/components/component.py
handle_paste
¶
select_value
¶
Select the visible item whose stored value equals value.
Returns True when a match is found. The stable way to keep a
selection pinned across item rebuilds: store the value, rebuild
items, then re-select by value.
Source code in xnano/components/options.py
resolve_submission
¶
Reconcile typed composer text with the selection per accept.
Removes the userland "did they Tab-complete this row or type past
it?" logic. See AcceptPolicy for the per-policy behavior.
Source code in xnano/components/options.py
move
¶
move(delta: int) -> None
Move selected by delta, skipping disabled entries.
Movement stays within the currently filtered choices.
Parameters:
-
delta(int) –Steps to move; negative moves toward the start.
Source code in xnano/components/options.py
select
¶
select(index: int) -> None
Set selected to index within the filtered view.
Disabled entries are rejected; the selection is left unchanged
when index points at a disabled item. Out-of-range indices
are clamped.
Parameters:
-
index(int) –Target index in the filtered view.
Source code in xnano/components/options.py
clear_query
¶
handle_hover
¶
Mark the row under the pointer as hovered (mouse hover).
Hover is a distinct indicator from the selection: the hovered row
is set here and drawn with a dim hover_symbol. Moving off the
rows clears it. Returns whether the hovered row changed.
Source code in xnano/components/options.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
Open, close, search, or move through the dropdown.
Opening keys expand a closed dropdown. Escape closes it without
changing the selection. Enter accepts the selected value and closes
it when close_on_select is enabled.
Parameters:
-
keyboard('KeyboardEventData') –The keyboard event payload.
Returns:
-
bool–Truewhen the event was consumed.
Source code in xnano/components/dropdown.py
compose
¶
compose(ctx: 'ComponentRenderContext') -> Any
Compose closed label or open options content.
Parameters:
-
ctx('ComponentRenderContext') –Render-time scope for this paint.
Returns:
-
Closed(Any) –a single
TextBlockrow. Open: the same content -
Any–tree
Optionswould produce, optionally windowed.
Source code in xnano/components/dropdown.py
Image
dataclass
¶
Image(
source: ImageSource = "",
fit: ImageFit = "crop",
loop: bool = True,
speed: float = 1.0,
background: tuple[int, int, int] = (0, 0, 0),
horizontal_pixels_per_cell: HorizontalPixelsPerCell = 1,
correct_terminal_aspect: bool = False,
playing: bool = True,
position_ms: float | None = None,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = False
)
Bases: Component
A native-resolution terminal image or real-time GIF component.
Pass an Image to a runtime render for a zero-delay still/first
frame. Animated formats play according to their source frame timings
when playing is True.
crop is intentionally the default fit: source pixels are never
resized. The source and viewport centers align, with oversized content
cropped and undersized content padded around the center.
Example
Image(source="logo.png", fit="contain")
Attributes:
-
source(ImageSource) –Encoded image path, bytes, stream, or decoded data.
-
fit(ImageFit) –Native crop, contain, cover, stretch, or adaptive placement.
-
loop(bool) –Whether an animation restarts after its final frame.
-
speed(float) –Playback-rate multiplier.
-
background(tuple[int, int, int]) –RGB color behind transparency and centered padding.
-
horizontal_pixels_per_cell(HorizontalPixelsPerCell) –One for lossless width or two for 2x2 source-pixel sampling.
-
correct_terminal_aspect(bool) –Whether to compensate 2x2 sampling for terminal cells that are approximately twice as tall as wide.
-
playing(bool) –Whether wall-clock time advances the animation.
-
position_ms(float | None) –Explicit playback position override in milliseconds.
Methods:
-
get_frame–Optional frame/panel chrome around composed content.
-
before_render–Called before rendering; returns the effective render area.
-
after_render–Called after rendering for optional post-paint work.
-
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).
-
handle_keyboard–Optional keyboard handler while focused.
-
handle_paste–Optional paste handler while focused.
-
component_post_init–Validate configuration and decode the initial source.
-
play–Resume animation from the current playback position.
-
pause–Freeze animation at the current playback position.
-
restart–Restart animation timing at the next render.
-
seek–Move playback to a source timestamp without delaying a render.
-
get_frame_index–Return the source frame active at an elapsed playback time.
-
get_size–Return the native terminal cell dimensions of the source.
-
compose–Compose the current timed frame for the target terminal area.
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.
source
class-attribute
instance-attribute
¶
source: ImageSource = ''
Encoded image path, bytes, stream, or decoded image data.
fit
class-attribute
instance-attribute
¶
fit: ImageFit = 'crop'
Native crop, contain, cover, stretch, or adaptive placement.
loop
class-attribute
instance-attribute
¶
loop: bool = True
Whether an animation restarts after its final frame.
background
class-attribute
instance-attribute
¶
RGB color behind transparency and centered padding.
horizontal_pixels_per_cell
class-attribute
instance-attribute
¶
horizontal_pixels_per_cell: HorizontalPixelsPerCell = 1
Adjacent source pixels sampled into each terminal cell.
correct_terminal_aspect
class-attribute
instance-attribute
¶
correct_terminal_aspect: bool = False
Whether 2x2 sampling preserves physical terminal proportions.
playing
class-attribute
instance-attribute
¶
playing: bool = True
Whether wall-clock time advances the animation.
position_ms
class-attribute
instance-attribute
¶
position_ms: float | None = None
Explicit playback position override in milliseconds.
fit_content
class-attribute
instance-attribute
¶
fit_content: bool = dataclasses.field(
default=False, kw_only=True
)
Whether layout should use the image's natural cell size.
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
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.
Source code in xnano/components/component.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
handle_paste
¶
component_post_init
¶
play
¶
Resume animation from the current playback position.
Source code in xnano/components/image.py
pause
¶
restart
¶
seek
¶
seek(position_ms: float) -> None
Move playback to a source timestamp without delaying a render.
Parameters:
-
position_ms(float) –Source animation timestamp in milliseconds.
Source code in xnano/components/image.py
get_frame_index
¶
Return the source frame active at an elapsed playback time.
Parameters:
-
elapsed_ms(float) –Playback time in milliseconds.
Returns:
-
int–The zero-based active frame index.
Source code in xnano/components/image.py
get_size
¶
get_size(ctx: ComponentRenderContext) -> Size
Return the native terminal cell dimensions of the source.
Source code in xnano/components/image.py
compose
¶
compose(ctx: ComponentRenderContext) -> CellCanvas
Compose the current timed frame for the target terminal area.
Source code in xnano/components/image.py
ImageData
dataclass
¶
ImageData(
width: int, height: int, frames: tuple[ImageFrame, ...]
)
Decoded image frames independent of Pillow and the render engine.
Attributes:
-
width(int) –Native pixel width shared by every frame.
-
height(int) –Native pixel height shared by every frame.
-
frames(tuple[ImageFrame, ...]) –RGB frames in playback order.
Methods:
-
from_bytes–Decode xnano's compact, Pillow-free animation container.
from_bytes
classmethod
¶
Decode xnano's compact, Pillow-free animation container.
Parameters:
-
data(bytes) –Bytes produced by
scripts/precompute_demo_image.py.
Returns:
-
ImageData–Decoded full-resolution RGB image data.
Source code in xnano/components/image.py
ImageFrame
dataclass
¶
One native-resolution RGB frame and its display duration.
Attributes:
-
pixels(bytes) –Packed row-major RGB bytes.
-
duration_ms(int) –Display duration in milliseconds.
Input
dataclass
¶
Input(
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,
submit_keys: Sequence[str] = ("enter",),
auto_height: bool = False,
min_rows: int = 1,
max_rows: int | None = None,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Text
Editable text field.
Input is single-line by default. Set multiline=True for an editor
that supports line breaks, selection, and navigation. Set
auto_height=True for a composer that grows as the text soft-wraps,
bounded by min_rows and max_rows — pair it with a
Field(height="fit") slot so layout consumes the reported height.
Example
Input(placeholder="Search", submit_keys=("enter",))
Attributes:
-
submit_keys(Sequence[str]) –Keys reserved for submit hooks instead of text editing.
-
auto_height(bool) –Grow the reported height to fit soft-wrapped content.
-
min_rows(int) –Minimum reported height when
auto_heightis set. -
max_rows(int | None) –Maximum reported height when
auto_heightis set.
Methods:
-
get_frame–Optional frame/panel chrome around composed content.
-
before_render–Called before rendering; returns the effective render area.
-
after_render–Record the multi-line editor caret so the terminal cursor tracks it.
-
compose–Compose interface-neutral content for this Text.
-
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).
-
handle_keyboard–Edit this text when it has focus.
-
handle_paste–Insert pasted text at the caret of a multi-line editor.
-
get_terminal_node–Return composed content for terminal compatibility.
-
component_post_init–Force input mode, then run
Texteditor setup. -
get_size–Report the preferred cell size, growing with content when asked.
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.
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.
submit_keys
class-attribute
instance-attribute
¶
Read-only convenience for hook matching; not consumed here.
auto_height
class-attribute
instance-attribute
¶
auto_height: bool = False
Report a preferred height that grows with soft-wrapped content.
Works with a Field(height="fit") slot: the input measures how many
rows its value occupies at the available width and reports that height,
clamped to [min_rows, max_rows] — no manual grid_set_field loop.
min_rows
class-attribute
instance-attribute
¶
min_rows: int = 1
Smallest reported height (rows) while auto_height is set.
max_rows
class-attribute
instance-attribute
¶
max_rows: int | None = None
Largest reported height (rows) while auto_height is set, or
None for unbounded growth.
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
Record the multi-line editor caret so the terminal cursor tracks it.
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
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.
Source code in xnano/components/component.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
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
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
component_post_init
¶
get_size
¶
get_size(ctx: 'ComponentRenderContext') -> Size
Report the preferred cell size, growing with content when asked.
Source code in xnano/components/input.py
Link
dataclass
¶
Link(
content: str | Text | list[str | Text] = "",
foreground: ColorLike | None = "blue",
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 = True,
fill: bool = False,
url: str = "",
underline: bool = True,
focused_color: ColorLike | None = None,
visited: bool = False,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Text
Focusable hyperlink label.
Links are underlined and blue by default. Handle an activation key in a
grid hook to open, copy, or otherwise use url.
Example
Link(content="Documentation", url="https://example.com/docs")
Attributes:
-
url(str) –Destination address exposed to hooks.
-
underline(bool) –When
True, paint with the underline modifier. -
focused_color(ColorLike | None) –Foreground override while focused.
-
visited(bool) –Whether the link has been activated by the app.
Methods:
-
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.
-
after_render–Record the multi-line editor caret so the terminal cursor tracks it.
-
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).
-
handle_paste–Insert pasted text at the caret of a multi-line editor.
-
get_terminal_node–Return composed content for terminal compatibility.
-
component_post_init–Validate modes without forcing
input=True. -
compose–Compose underlined, focus-aware link content.
-
handle_keyboard–Leave activation keys for application hooks.
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.
content
class-attribute
instance-attribute
¶
Plain string, nested Text, or a list of either.
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.
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.
url
class-attribute
instance-attribute
¶
url: str = ''
Destination address exposed to hooks; never auto-opened.
underline
class-attribute
instance-attribute
¶
underline: bool = True
When True, compose with the underline modifier.
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = 'blue'
Default link foreground color.
focused_color
class-attribute
instance-attribute
¶
focused_color: ColorLike | None = None
Foreground override while this link holds focus.
visited
class-attribute
instance-attribute
¶
visited: bool = False
Application-maintained visited flag.
focusable
class-attribute
instance-attribute
¶
focusable: bool = True
Links participate in field focus by default.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
Record the multi-line editor caret so the terminal cursor tracks it.
Source code in xnano/components/text.py
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.
Source code in xnano/components/component.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
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
component_post_init
¶
compose
¶
compose(
ctx: ComponentRenderContext[Any],
) -> TextBlock | Any
Compose underlined, focus-aware link content.
Parameters:
-
ctx(ComponentRenderContext[Any]) –Render-time scope for this paint.
Returns:
Source code in xnano/components/link.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
Leave activation keys for application hooks.
Parameters:
-
keyboard('KeyboardEventData') –The keyboard event payload.
Returns:
-
bool–Always
Falseso enter/space and other keys bubble.
Source code in xnano/components/link.py
Loader
dataclass
¶
Loader(
value: float | None = None,
total: float | None = None,
style: LoaderStyle = "spinner",
label: LoaderLabel = None,
symbols: LoaderSymbols = "dots",
interval: int = 80,
foreground: "ColorLike" = "green",
background: "ColorLike | None" = None,
filled_color: "ColorLike | None" = None,
unfilled_color: "ColorLike | None" = None,
running: bool = True,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = False
)
Bases: Component
Determinate progress indicator or indeterminate spinner.
Leave value as None to show a spinner. Set value to a ratio,
or pair it with total, to show measurable progress.
Example
Loader(value=42, total=100, label=True)
Attributes:
-
value(float | None) –Current amount, ratio, or
Nonefor indeterminate. -
total(float | None) –When set, ratio is
value / total. -
style(LoaderStyle) –"spinner","bar", or"line". -
label(LoaderLabel) –Overlay text, auto percentage, nested Text, or hidden.
-
symbols(LoaderSymbols) –Spinner frames or a named preset.
-
interval(int) –Milliseconds between spinner frames.
-
foreground('ColorLike') –Primary foreground / filled color (deprecated alias:
color). -
background('ColorLike | None') –Widget background color.
-
filled_color('ColorLike | None') –Line style filled-portion color.
-
unfilled_color('ColorLike | None') –Line style unfilled-portion color.
-
running(bool) –Whether spinner animation advances.
Methods:
-
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.
-
after_render–Called after rendering for optional post-paint work.
-
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).
-
handle_keyboard–Optional keyboard handler while focused.
-
handle_paste–Optional paste handler while focused.
-
component_post_init–Resolve spinner frames and start the animation epoch.
-
restart–Reset the spinner epoch to the current monotonic time.
-
current_frame–Return the active spinner glyph, advanced by the framework clock.
-
inline_text–Return the spinner glyph plus its label for inline embedding.
-
compose–Compose spinner text or gauge content for this loader.
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.
value
class-attribute
instance-attribute
¶
value: float | None = None
Current amount, ratio, or None for indeterminate work.
total
class-attribute
instance-attribute
¶
total: float | None = None
When set, the ratio is value / total.
style
class-attribute
instance-attribute
¶
style: LoaderStyle = 'spinner'
"spinner", block "bar", or thin "line" gauge.
label
class-attribute
instance-attribute
¶
label: LoaderLabel = None
Overlay text. None auto-derives a percentage when determinate.
symbols
class-attribute
instance-attribute
¶
symbols: LoaderSymbols = 'dots'
Spinner frames or a named preset.
interval
class-attribute
instance-attribute
¶
interval: int = 80
Milliseconds between spinner frames.
foreground
class-attribute
instance-attribute
¶
Primary foreground / filled color (deprecated alias: color).
background
class-attribute
instance-attribute
¶
Widget background color.
filled_color
class-attribute
instance-attribute
¶
Line style filled-portion color (defaults to foreground).
unfilled_color
class-attribute
instance-attribute
¶
Line style unfilled-portion color.
running
class-attribute
instance-attribute
¶
running: bool = True
Whether spinner animation advances with wall time.
fit_content
class-attribute
instance-attribute
¶
fit_content: bool = dataclasses.field(
default=False, kw_only=True
)
Whether layout should use the loader's natural size.
ratio
property
¶
ratio: float
Return the completion ratio, clamped to 0.0–1.0.
Indeterminate loaders report 0.0.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
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.
Source code in xnano/components/component.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
handle_paste
¶
component_post_init
¶
Resolve spinner frames and start the animation epoch.
Source code in xnano/components/loader.py
restart
¶
current_frame
¶
current_frame() -> str
Return the active spinner glyph, advanced by the framework clock.
The inline path: embed this in any Text/flow content to animate a
spinner mid-line without a manual per-tick frame counter — e.g.
Text(content=f"{loader.current_frame()} generating…").
Source code in xnano/components/loader.py
compose
¶
Compose spinner text or gauge content for this loader.
Returns:
-
–
Interface-neutral content for this loader.
Source code in xnano/components/loader.py
Markdown
dataclass
¶
Markdown(
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,
base_path: Path | None = None,
images: bool = True,
links: bool = True,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Text
Display Markdown with terminal-friendly styling.
Content remains live and supports the same color, alignment, and wrapping
options as Text.
Example
Markdown(content="# Status\n\nAll systems operational.")
Attributes:
-
base_path(Path | None) –Root for resolving relative image and link targets.
-
images(bool) –When
True, allow image constructs when supported. -
links(bool) –When
True, allow link constructs when supported.
Methods:
-
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.
-
after_render–Record the multi-line editor caret so the terminal cursor tracks it.
-
compose–Compose interface-neutral content for this Text.
-
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).
-
handle_keyboard–Edit this text when it has focus.
-
handle_paste–Insert pasted text at the caret of a multi-line editor.
-
get_terminal_node–Return composed content for terminal compatibility.
-
component_post_init–Force markdown mode, then run
Textsetup.
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.
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.
base_path
class-attribute
instance-attribute
¶
base_path: Path | None = None
Root path for resolving relative image and link targets.
images
class-attribute
instance-attribute
¶
images: bool = True
Whether image constructs may be emitted when supported.
links
class-attribute
instance-attribute
¶
links: bool = True
Whether link constructs may be emitted when supported.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
Record the multi-line editor caret so the terminal cursor tracks it.
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
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.
Source code in xnano/components/component.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
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
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
Option
dataclass
¶
A labeled choice with optional distinct value and disabled flag.
Pass plain strings or Text values for simple choices. Use Option
when the stored value differs from its label or the choice is disabled.
Attributes:
-
label(str | Any) –Display text (plain string or styled
Textleaf). -
value(Any) –Stored value; defaults to the plain label text when
None. -
disabled(bool) –When
True, movement skips this entry and it cannot become the active selection viaselect.
Methods:
-
get_label_text–Return the plain-text form of
label. -
get_value–Return the stored value, falling back to the plain label.
value
class-attribute
instance-attribute
¶
value: Any = None
Stored value; defaults to the plain label text when None.
disabled
class-attribute
instance-attribute
¶
disabled: bool = False
When True, movement skips this entry.
get_label_text
¶
get_label_text() -> str
Return the plain-text form of label.
Source code in xnano/components/options.py
Options
dataclass
¶
Options(
items: Sequence[OptionItem] = (),
query: str = "",
filter: FilterMode = "fuzzy",
accept: AcceptPolicy = "replace",
searchable: bool = False,
selected: int = 0,
direction: OptionsDirection = "top_to_bottom",
foreground: ColorLike | None = None,
background: ColorLike | None = None,
highlight_color: ColorLike = "black",
highlight_background: ColorLike = "white",
highlight_symbol: str = "> ",
hovered: int | None = None,
hover_symbol: str = "· ",
match_color: ColorLike | None = "cyan",
repeat_highlight_symbol: bool = False,
focusable: bool = True,
passthrough: Sequence[str] = (),
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Component
Always-visible, selectable choice list.
Up/down move the selection (skipping disabled entries) and value
reads the selected item:
class Picker(BaseGrid):
themes: Options = Field(
default=Options(items=THEME_NAMES),
)
@on_keyboard("enter")
def _choose(self, ctx: Context) -> None:
apply_theme(self.themes.value)
A plain list is not a search box: typing-to-filter is opt-in. Set
searchable=True to turn the list into a fuzzy filter where printable
keys edit query and matched characters are emphasized in
match_color — a focused searchable list intentionally consumes those
keys, so leave it off for a list that only browses, or the keys never
reach your command hooks. Either way you can drive query reactively
from another field.
Example
Options(items=("small", "medium", "large"), selected=1)
Attributes:
-
items(Sequence[OptionItem]) –Entries to pick from (strings,
Text, orOption). -
query(str) –Filter text edited by typing when
searchable. -
filter(FilterMode) –Whether
queryfuzzy-filters the visible items. -
searchable(bool) –Whether typing while focused edits
query(opt-in; defaults toFalseso a plain list does not swallow keys). -
selected(int) –Selection index within the filtered view.
-
direction(OptionsDirection) –Visual order of option rows.
-
foreground(ColorLike | None) –Default foreground color for unselected rows (deprecated alias:
color). -
background(ColorLike | None) –Default background color for unselected rows.
-
highlight_color(ColorLike) –Foreground of the selected row.
-
highlight_background(ColorLike) –Background of the selected row.
-
highlight_symbol(str) –Symbol prepended to the selected row.
-
hovered(int | None) –Row under the pointer (filtered-view index), or
None. -
hover_symbol(str) –Dim symbol prepended to the hovered row.
-
match_color(ColorLike | None) –Emphasis color for characters matched by
query. -
repeat_highlight_symbol(bool) –When
True, every row shows the highlight symbol (selected row still uses highlight style). -
focusable(bool) –Whether this Options participates in field focus.
-
passthrough(Sequence[str]) –Key bindings never captured while focused.
Methods:
-
component_post_init–Initialize subclass state after dataclass fields are assigned.
-
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).
-
handle_paste–Optional paste handler while focused.
-
select_value–Select the visible item whose stored value equals
value. -
resolve_submission–Reconcile typed composer text with the selection per
accept. -
move–Move
selectedbydelta, skipping disabled entries. -
select–Set
selectedtoindexwithin the filtered view. -
clear_query–Clear the filter query and reset selection to the first row.
-
handle_keyboard–Apply a keyboard event while this Options is focused.
-
compose–Compose interface-neutral Content for this Options.
-
after_render–Record the painted area so hover can map a pointer to a row.
-
handle_hover–Mark the row under the pointer as hovered (mouse hover).
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.
items
class-attribute
instance-attribute
¶
items: Sequence[OptionItem] = ()
Entries to pick from (plain strings, Text, or Option).
query
class-attribute
instance-attribute
¶
query: str = ''
Filter text. Edited by typing while focused when searchable;
assign it from a hook to filter reactively.
filter
class-attribute
instance-attribute
¶
filter: FilterMode = 'fuzzy'
How query narrows the visible items — see FilterMode.
"fuzzy"/True fuzzy-match, "prefix" prefix-match, "none"/
False show everything (for externally filtered items), or a
(query, item_text) -> bool callable.
accept
class-attribute
instance-attribute
¶
accept: AcceptPolicy = 'replace'
How resolve_submission reconciles typed text with the selection.
searchable
class-attribute
instance-attribute
¶
searchable: bool = False
Whether typing while focused edits query directly.
Off by default: a plain Options browses with the arrow keys and lets
every other key reach app hooks. Turn it on to make the list a fuzzy
search box that consumes printable keys while focused.
selected
class-attribute
instance-attribute
¶
selected: int = 0
Selection index within the filtered view.
direction
class-attribute
instance-attribute
¶
direction: OptionsDirection = 'top_to_bottom'
Visual order of option rows in the list.
foreground
class-attribute
instance-attribute
¶
foreground: ColorLike | None = None
Default foreground color for unselected rows (deprecated alias:
color).
background
class-attribute
instance-attribute
¶
background: ColorLike | None = None
Default background color for unselected rows.
highlight_color
class-attribute
instance-attribute
¶
highlight_color: ColorLike = 'black'
Foreground of the selected row.
highlight_background
class-attribute
instance-attribute
¶
highlight_background: ColorLike = 'white'
Background of the selected row.
highlight_symbol
class-attribute
instance-attribute
¶
highlight_symbol: str = '> '
Symbol prepended to the selected row.
hovered
class-attribute
instance-attribute
¶
hovered: int | None = None
Row under the pointer (filtered-view index), or None.
Set by :meth:handle_hover when mouse events are enabled; drawn as a
dim hover_symbol so it reads as distinct from the selection.
hover_symbol
class-attribute
instance-attribute
¶
hover_symbol: str = '· '
Symbol prepended to the hovered row (dim), distinct from selection.
match_color
class-attribute
instance-attribute
¶
match_color: ColorLike | None = 'cyan'
Emphasis color for characters matched by query.
repeat_highlight_symbol
class-attribute
instance-attribute
¶
repeat_highlight_symbol: bool = False
When True, every row shows the highlight symbol.
focusable
class-attribute
instance-attribute
¶
focusable: bool = True
Whether this Options participates in field focus (tab order).
passthrough
class-attribute
instance-attribute
¶
Key bindings this list never captures while focused.
owns_cursor
class-attribute
instance-attribute
¶
owns_cursor: bool = dataclasses.field(
default=True, init=False
)
Whether selection replaces the hardware caret.
filtered
property
¶
Indices into items currently visible, in display order.
Use this with visible_items to inspect the current filtered view.
visible_items
property
¶
Plain text of the currently visible items, in display order.
selected_item
property
¶
selected_item: OptionItem | None
The selected item object, or None when the view is empty.
selected_value
property
¶
selected_value: Any | None
Stable stored value of the selection (alias of value).
Use with select_value to preserve a selection across item
rebuilds by value/id rather than by fragile filtered index.
selected_label
property
¶
selected_label: str
Plain display text of the selected item, or "" when empty.
component_post_init
¶
Initialize subclass state after dataclass fields are assigned.
Override this method instead of __post_init__.
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.
Source code in xnano/components/component.py
handle_paste
¶
select_value
¶
Select the visible item whose stored value equals value.
Returns True when a match is found. The stable way to keep a
selection pinned across item rebuilds: store the value, rebuild
items, then re-select by value.
Source code in xnano/components/options.py
resolve_submission
¶
Reconcile typed composer text with the selection per accept.
Removes the userland "did they Tab-complete this row or type past
it?" logic. See AcceptPolicy for the per-policy behavior.
Source code in xnano/components/options.py
move
¶
move(delta: int) -> None
Move selected by delta, skipping disabled entries.
Movement stays within the currently filtered choices.
Parameters:
-
delta(int) –Steps to move; negative moves toward the start.
Source code in xnano/components/options.py
select
¶
select(index: int) -> None
Set selected to index within the filtered view.
Disabled entries are rejected; the selection is left unchanged
when index points at a disabled item. Out-of-range indices
are clamped.
Parameters:
-
index(int) –Target index in the filtered view.
Source code in xnano/components/options.py
clear_query
¶
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
Apply a keyboard event while this Options is focused.
Up/down move the selection (skipping disabled); Home/End jump
to the first/last enabled entry. Printable characters and
backspace edit query when searchable. Enter, tab,
escape, and passthrough bindings are never consumed so hooks
and focus navigation see them.
Parameters:
-
keyboard('KeyboardEventData') –The keyboard event payload.
Returns:
-
bool–Truewhen the event was consumed.
Source code in xnano/components/options.py
compose
¶
compose(ctx: 'ComponentRenderContext') -> Any
Compose interface-neutral Content for this Options.
Parameters:
-
ctx('ComponentRenderContext') –Render-time scope for this paint.
Returns:
Source code in xnano/components/options.py
handle_hover
¶
Mark the row under the pointer as hovered (mouse hover).
Hover is a distinct indicator from the selection: the hovered row
is set here and drawn with a dim hover_symbol. Moving off the
rows clears it. Returns whether the hovered row changed.
Source code in xnano/components/options.py
Scrollbar
dataclass
¶
Scrollbar(
content_length: int = 0,
position: int = 0,
viewport_length: int = 0,
orientation: ScrollbarOrientationLike = "vertical_right",
thumb: str | None = None,
track: str | None = None,
begin: str | None = None,
end: str | None = None,
color: "ColorLike | None" = None,
thumb_color: "ColorLike | None" = None,
track_color: "ColorLike | None" = None,
begin_color: "ColorLike | None" = None,
end_color: "ColorLike | None" = None,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Component
Display the visible range of scrollable content.
Lengths and position are clamped on every frame, so live updates cannot move the thumb outside the track.
Example
Scrollbar(content_length=200, viewport_length=25, position=50)
Attributes:
-
content_length(int) –Total scrollable content size.
-
position(int) –Current scroll offset within
content_length. -
viewport_length(int) –Visible window size; drives thumb proportion.
-
orientation(ScrollbarOrientationLike) –Which edge the scrollbar is drawn on.
-
thumb(str | None) –Optional thumb glyph.
-
track(str | None) –Optional track glyph.
-
begin(str | None) –Arrow symbol at the start;
Noneomits it. -
end(str | None) –Arrow symbol at the end;
Noneomits it. -
color('ColorLike | None') –Overall track and thumb style.
-
thumb_color('ColorLike | None') –Thumb foreground color.
-
track_color('ColorLike | None') –Track foreground color.
-
begin_color('ColorLike | None') –Begin-arrow color.
-
end_color('ColorLike | None') –End-arrow color.
Methods:
-
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.
-
after_render–Called after rendering for optional post-paint work.
-
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).
-
handle_keyboard–Optional keyboard handler while focused.
-
handle_paste–Optional paste handler while focused.
-
component_post_init–Clamp initial lengths and position.
-
from_scroll_handle–Build a scrollbar bound to a field scroll handle.
-
compose–Compose scrollbar content with a native paint fallback.
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.
content_length
class-attribute
instance-attribute
¶
content_length: int = 0
Total scrollable content size.
position
class-attribute
instance-attribute
¶
position: int = 0
Current scroll offset within content_length.
viewport_length
class-attribute
instance-attribute
¶
viewport_length: int = 0
Visible window size; drives thumb proportion.
orientation
class-attribute
instance-attribute
¶
orientation: ScrollbarOrientationLike = 'vertical_right'
Which edge the scrollbar is drawn on.
begin
class-attribute
instance-attribute
¶
begin: str | None = None
Arrow symbol at the start; None omits it.
end
class-attribute
instance-attribute
¶
end: str | None = None
Arrow symbol at the end; None omits it.
color
class-attribute
instance-attribute
¶
Overall track and thumb style.
thumb_color
class-attribute
instance-attribute
¶
Thumb foreground color.
track_color
class-attribute
instance-attribute
¶
Track foreground color.
begin_color
class-attribute
instance-attribute
¶
Begin-arrow color.
end_color
class-attribute
instance-attribute
¶
End-arrow color.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
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.
Source code in xnano/components/component.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
handle_paste
¶
component_post_init
¶
from_scroll_handle
classmethod
¶
from_scroll_handle(
handle: "ScrollHandle",
*,
content_length: int | None = None,
viewport_length: int | None = None,
orientation: ScrollbarOrientationLike = "vertical_right",
thumb: str | None = None,
track: str | None = None,
begin: str | None = None,
end: str | None = None,
color: "ColorLike | None" = None,
thumb_color: "ColorLike | None" = None,
track_color: "ColorLike | None" = None,
begin_color: "ColorLike | None" = None,
end_color: "ColorLike | None" = None,
visible: bool = True,
z: int = 0,
fit_content: bool = True
) -> "Scrollbar"
Build a scrollbar bound to a field scroll handle.
The handle owns offset / follow mode. Callers (or the field controller) should pass the measured content and viewport lengths; the component never reaches into grid private dictionaries.
Parameters:
-
handle('ScrollHandle') –Resolved
ScrollHandlefor a scrolled field. -
content_length(int | None, default:None) –Total scrollable content size when known.
-
viewport_length(int | None, default:None) –Visible window size when known.
-
orientation(ScrollbarOrientationLike, default:'vertical_right') –Scrollbar edge placement.
-
thumb(str | None, default:None) –Optional thumb glyph.
-
track(str | None, default:None) –Optional track glyph.
-
begin(str | None, default:None) –Optional leading glyph.
-
end(str | None, default:None) –Optional trailing glyph.
-
color('ColorLike | None', default:None) –Overall foreground color.
-
thumb_color('ColorLike | None', default:None) –Thumb foreground color.
-
track_color('ColorLike | None', default:None) –Track foreground color.
-
begin_color('ColorLike | None', default:None) –Leading glyph color.
-
end_color('ColorLike | None', default:None) –Trailing glyph color.
-
visible(bool, default:True) –Whether the scrollbar paints.
-
z(int, default:0) –Paint order relative to siblings.
-
fit_content(bool, default:True) –Whether layout uses the natural scrollbar size.
Returns:
-
'Scrollbar'–A
Scrollbarthat readspositionfromhandle.
Source code in xnano/components/scrollbar.py
compose
¶
Compose scrollbar content with a native paint fallback.
Returns:
-
–
Interface-neutral content for this scrollbar.
Column
dataclass
¶
Column(
header: str | None = None,
accessor: Callable[[Any], Any] | None = None,
format: FormatResolver = None,
foreground: ColorResolver = None,
background: ColorResolver = None,
horizontal_align: "Alignment | None" = None,
width: int | float | None = None,
)
Bases: ComponentDescriptor
Describe one table column.
Attributes:
-
header(str | None) –Header displayed for the column.
-
accessor(Callable[[Any], Any] | None) –Row attribute, mapping key, or value callback.
-
format(FormatResolver) –Optional format string or value callback.
-
foreground(ColorResolver) –Cell foreground color.
-
background(ColorResolver) –Cell background color.
-
horizontal_align('Alignment | None') –Cell alignment.
-
width(int | float | None) –Fixed or proportional column width.
Methods:
-
resolve_header–Return the displayed header.
-
resolve_value–Read this column's value from a row.
-
resolve_text–Format a value for display.
-
resolve_color–Resolve the foreground color for a value.
-
resolve_background–Resolve the background color for a value.
name
class-attribute
instance-attribute
¶
name: str = dataclasses.field(default='', init=False)
Attribute name assigned by the component class.
accessor
class-attribute
instance-attribute
¶
Custom row value accessor.
foreground
class-attribute
instance-attribute
¶
Foreground color or resolver.
background
class-attribute
instance-attribute
¶
Background color or resolver.
horizontal_align
class-attribute
instance-attribute
¶
Cell text alignment.
width
class-attribute
instance-attribute
¶
Fixed width or fractional width.
resolve_value
¶
Read this column's value from a row.
resolve_text
¶
Format a value for display.
Source code in xnano/components/schema.py
resolve_color
¶
resolve_background
¶
Table
dataclass
¶
Table(
data: list[Any] = list(),
columns: ColumnsArg = None,
selected: int | None = None,
show_header: bool = True,
column_spacing: int = 1,
highlight_color: "ColorLike | None" = None,
highlight_background: "ColorLike | None" = None,
highlight_symbol: str | None = None,
focusable: bool = False,
passthrough: Sequence[str] = (),
sort: str | None = None,
sort_direction: SortDirection = "ascending",
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Component
Declarative data table.
Feed it a list of rows — dicts, dataclasses, or arbitrary objects —
and the columns are derived for you. Selection is a single attribute.
For full control, subclass and declare Column descriptors.
Example
Table(data=({"name": "Ada", "role": "Engineer"},))
Attributes:
-
data(list[Any]) –The rows — dicts, dataclasses, or objects with attributes.
-
columns(ColumnsArg) –Optional column overrides for the data-driven path.
-
selected(int | None) –Highlighted row index in display order.
-
show_header(bool) –Whether to render the derived header row.
-
column_spacing(int) –Space between columns in terminal columns.
-
highlight_color('ColorLike | None') –Selection foreground color.
-
highlight_background('ColorLike | None') –Selection background color.
-
highlight_symbol(str | None) –Glyph prepended to the selected row.
-
focusable(bool) –Whether keyboard navigation is enabled.
-
passthrough(Sequence[str]) –Key bindings that bubble without being consumed.
-
sort(str | None) –Optional column name used for a derived sort index.
-
sort_direction(SortDirection) –Ascending or descending sort order.
Methods:
-
component_post_init–Initialize subclass state after dataclass fields are assigned.
-
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.
-
after_render–Called after rendering for optional post-paint work.
-
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).
-
handle_paste–Optional paste handler while focused.
-
move–Move the selection by
deltarows in display order. -
handle_keyboard–Navigate selection when
focusableis enabled. -
compose–Compose TableGrid content with a native TableNode paint fallback.
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.
data
class-attribute
instance-attribute
¶
data: list[Any] = dataclasses.field(default_factory=list)
The rows — dicts, dataclasses, or objects with attributes.
columns
class-attribute
instance-attribute
¶
columns: ColumnsArg = None
Optional column overrides for the data-driven path.
selected
class-attribute
instance-attribute
¶
selected: int | None = None
Highlighted row index in display order.
show_header
class-attribute
instance-attribute
¶
show_header: bool = True
Whether to render the derived header row.
column_spacing
class-attribute
instance-attribute
¶
column_spacing: int = 1
Space between columns in terminal columns.
highlight_color
class-attribute
instance-attribute
¶
Selection foreground color.
highlight_background
class-attribute
instance-attribute
¶
Selection background color.
highlight_symbol
class-attribute
instance-attribute
¶
highlight_symbol: str | None = None
Glyph prepended to the selected row.
focusable
class-attribute
instance-attribute
¶
focusable: bool = False
Whether keyboard navigation is enabled.
passthrough
class-attribute
instance-attribute
¶
Key bindings that bubble without being consumed.
sort
class-attribute
instance-attribute
¶
sort: str | None = None
Optional column name used for a derived sort index.
sort_direction
class-attribute
instance-attribute
¶
sort_direction: SortDirection = 'ascending'
Ascending or descending sort order.
component_post_init
¶
Initialize subclass state after dataclass fields are assigned.
Override this method instead of __post_init__.
get_size
¶
get_size(ctx: ComponentRenderContext[StateT]) -> Size
before_render
¶
before_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"
after_render
¶
after_render(
ctx: ComponentRenderContext[StateT], area: "Area"
) -> None
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.
Source code in xnano/components/component.py
handle_paste
¶
move
¶
Move the selection by delta rows in display order.
Parameters:
-
delta(int) –Positive moves down; negative moves up.
Returns:
-
int | None–The new selected index, or
Nonewhen there is no data.
Source code in xnano/components/table.py
handle_keyboard
¶
handle_keyboard(keyboard: 'KeyboardEventData') -> bool
Navigate selection when focusable is enabled.
Returns:
-
bool–Truewhen the event was consumed.
Source code in xnano/components/table.py
compose
¶
Compose TableGrid content with a native TableNode paint fallback.
Returns:
-
–
Interface-neutral content for this table.
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:
-
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).
-
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.
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.
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.
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.
Source code in xnano/components/component.py
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: