xnano.components.table
xnano.components.table
¶
xnano.components.table
Render mappings, dataclasses, or objects as a sortable data table.
Classes:
Attributes:
-
ColumnsArg(TypeAlias) –Optional column overrides for the data-driven
Tablepath. -
SortDirection(TypeAlias) –Sort order applied to a derived row index without mutating data.
ColumnsArg
module-attribute
¶
ColumnsArg: TypeAlias = (
"dict[str, Column | str | Callable[[Any], Any]] | list[str] | None"
)
Optional column overrides for the data-driven Table path.
SortDirection
module-attribute
¶
Sort order applied to a derived row index without mutating data.
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:
-
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.
-
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.
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.
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.
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.
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.