xnano.core.demo
xnano.core.demo
¶
xnano.core.demo
Entry point for the bundled showcase and the Markdown document viewer.
With no arguments this runs the feature showcase: a mosaic of differently
sized boxes, several with their own inner tabs and effects, driven entirely
through xnano. The whole scene stays fluid because every animated box
follows one rule — a per-pixel CellCanvas is built once and stored on its
component, then returned unchanged from compose until a throttled tick
rebuilds it. The renderer caches lowered canvas IR by object identity, so
reusing the same canvas between rebuilds is a cache hit rather than a full
re-lowering every frame.
Classes:
-
Showcase–The full showcase: header, the box mosaic, and a keybind legend.
-
Demo–The full experience: a title splash that gives way to the mosaic.
Functions:
-
run_showcase–Run the feature showcase on the live terminal.
-
run_demo–Run the feature showcase, or view a Markdown document.
AnimatedCanvas
dataclass
¶
AnimatedCanvas(
mode: str = "Plasma",
phase: float = 0.0,
*,
visible: bool = True,
z: int = 0,
fit_content: bool = True
)
Bases: Component
A stored, tick-rebuilt canvas that renders one of the stage modes.
compose returns the same :class:CellCanvas between rebuilds so the
renderer's identity cache stays warm; rebuild swaps in a fresh canvas
from a throttled tick.
Methods:
-
rebuild–Rebuild and store the canvas for the current mode and phase.
-
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.
Attributes:
-
visible(bool) –Whether this component paints at all.
-
z(int) –Stacking order among sibling content.
-
fit_content(bool) –When
True, paint at natural size inside a larger slot. -
focused(bool) –Whether this component currently holds field focus.
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.
rebuild
¶
Rebuild and store the canvas for the current mode and phase.
Source code in xnano/core/demo.py
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
IntroSplash
dataclass
¶
Bases: Component
The opening title splash: an animated .xni clip with the xnano
wordmark centered over it on a higher z.
The wordmark is a transparent glyph overlay — a small, fixed-position node that paints only its letters, so the clip keeps animating through the gaps with no band around the text. Falls back to the plasma title when the clip cannot be decoded.
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.
Attributes:
-
visible(bool) –Whether this component paints at all.
-
z(int) –Stacking order among sibling content.
-
fit_content(bool) –When
True, paint at natural size inside a larger slot. -
focused(bool) –Whether this component currently holds field focus.
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_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
MetricsPanel
dataclass
¶
Bases: Component
Three live line gauges that drift off the wall clock — paint budget, memory, and frame rate.
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.
Attributes:
-
visible(bool) –Whether this component paints at all.
-
z(int) –Stacking order among sibling content.
-
fit_content(bool) –When
True, paint at natural size inside a larger slot. -
focused(bool) –Whether this component currently holds field focus.
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_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
StageBox
¶
Bases: BaseGrid
The large center stage: an animated canvas with three inner tabs.
Methods:
-
select_tab–Set the stage animation mode and force an immediate rebuild.
-
cycle_tab–Switch the stage animation mode by
deltatabs. -
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_post_init–Called exactly once, when this grid is first attached to a live
-
grid_render–Called each frame before layout.
-
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
select_tab
¶
select_tab(index: int) -> None
Set the stage animation mode and force an immediate rebuild.
Source code in xnano/core/demo.py
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_post_init
¶
Called exactly once, when this grid is first attached to a live terminal — after its own hooks are bound, before its first paint.
Unlike __post_init__ (construction time, no terminal attached
yet), ctx/ctx.state are live here. Override with either
signature — the extra parameter is optional, matching every other
@on_* hook, dispatched by arity at runtime (see _call_hook):
def grid_post_init(self) -> None: ...
def grid_post_init(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override (this base declares zero); that's a known false positive
for this flexible-arity hook pattern — add
# ty: ignore[invalid-method-override] on the override line.
Source code in xnano/grids.py
grid_render
¶
Called each frame before layout.
Override to refresh field values every frame. Initial values can be set
with Field(default=...), default_factory, or __post_init__.
Override with either signature — the extra Context parameter is
optional, dispatched by arity like grid_post_init:
def grid_render(self) -> None: ...
def grid_render(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override; add # ty: ignore[invalid-method-override] on the
override line.
Source code in xnano/grids.py
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
OrbitBox
¶
Bases: BaseGrid
A drifting canvas with three motion tabs of its own.
Methods:
-
select_tab–Set the orbit motion pattern and force an immediate rebuild.
-
cycle_tab–Rotate the orbit motion pattern by
deltatabs. -
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_post_init–Called exactly once, when this grid is first attached to a live
-
grid_render–Called each frame before layout.
-
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
select_tab
¶
select_tab(index: int) -> None
Set the orbit motion pattern and force an immediate rebuild.
Source code in xnano/core/demo.py
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_post_init
¶
Called exactly once, when this grid is first attached to a live terminal — after its own hooks are bound, before its first paint.
Unlike __post_init__ (construction time, no terminal attached
yet), ctx/ctx.state are live here. Override with either
signature — the extra parameter is optional, matching every other
@on_* hook, dispatched by arity at runtime (see _call_hook):
def grid_post_init(self) -> None: ...
def grid_post_init(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override (this base declares zero); that's a known false positive
for this flexible-arity hook pattern — add
# ty: ignore[invalid-method-override] on the override line.
Source code in xnano/grids.py
grid_render
¶
Called each frame before layout.
Override to refresh field values every frame. Initial values can be set
with Field(default=...), default_factory, or __post_init__.
Override with either signature — the extra Context parameter is
optional, dispatched by arity like grid_post_init:
def grid_render(self) -> None: ...
def grid_render(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override; add # ty: ignore[invalid-method-override] on the
override line.
Source code in xnano/grids.py
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
SignalBox
¶
Bases: BaseGrid
Live signal box with Wave, Bars, and Spark inner tabs.
Methods:
-
select_tab–Select the wave, bar, or spark view by tab index.
-
cycle_tab–Rotate through the signal views.
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
PalettePanel
dataclass
¶
Bases: Component
A static color-palette swatch strip — every good TUI has one.
The swatch canvas is stored and only rebuilt when the box is resized, so it reuses the same cached object every frame.
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.
Attributes:
-
visible(bool) –Whether this component paints at all.
-
z(int) –Stacking order among sibling content.
-
fit_content(bool) –When
True, paint at natural size inside a larger slot. -
focused(bool) –Whether this component currently holds field focus.
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_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
DeckBox
¶
Bases: BaseGrid
A three-tab reference deck: overview text, a table, and code.
Methods:
-
select_tab–Select a deck tab by index.
-
cycle_tab–Rotate through the deck tabs.
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_post_init–Called exactly once, when this grid is first attached to a live
-
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_post_init
¶
Called exactly once, when this grid is first attached to a live terminal — after its own hooks are bound, before its first paint.
Unlike __post_init__ (construction time, no terminal attached
yet), ctx/ctx.state are live here. Override with either
signature — the extra parameter is optional, matching every other
@on_* hook, dispatched by arity at runtime (see _call_hook):
def grid_post_init(self) -> None: ...
def grid_post_init(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override (this base declares zero); that's a known false positive
for this flexible-arity hook pattern — add
# ty: ignore[invalid-method-override] on the override line.
Source code in xnano/grids.py
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
LogBox
¶
Bases: BaseGrid
A rolling event log, appended to as keybinds fire.
Methods:
-
append–Record one event line.
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
LeftColumn
¶
Bases: BaseGrid
Narrow rail: metrics over the event log.
Methods:
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_post_init–Called exactly once, when this grid is first attached to a live
-
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_post_init
¶
Called exactly once, when this grid is first attached to a live terminal — after its own hooks are bound, before its first paint.
Unlike __post_init__ (construction time, no terminal attached
yet), ctx/ctx.state are live here. Override with either
signature — the extra parameter is optional, matching every other
@on_* hook, dispatched by arity at runtime (see _call_hook):
def grid_post_init(self) -> None: ...
def grid_post_init(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override (this base declares zero); that's a known false positive
for this flexible-arity hook pattern — add
# ty: ignore[invalid-method-override] on the override line.
Source code in xnano/grids.py
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
CenterColumn
¶
Bases: BaseGrid
The main column: the stage over a signal/orbit strip.
Methods:
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_post_init–Called exactly once, when this grid is first attached to a live
-
grid_render–Called each frame before layout.
-
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_post_init
¶
Called exactly once, when this grid is first attached to a live terminal — after its own hooks are bound, before its first paint.
Unlike __post_init__ (construction time, no terminal attached
yet), ctx/ctx.state are live here. Override with either
signature — the extra parameter is optional, matching every other
@on_* hook, dispatched by arity at runtime (see _call_hook):
def grid_post_init(self) -> None: ...
def grid_post_init(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override (this base declares zero); that's a known false positive
for this flexible-arity hook pattern — add
# ty: ignore[invalid-method-override] on the override line.
Source code in xnano/grids.py
grid_render
¶
Called each frame before layout.
Override to refresh field values every frame. Initial values can be set
with Field(default=...), default_factory, or __post_init__.
Override with either signature — the extra Context parameter is
optional, dispatched by arity like grid_post_init:
def grid_render(self) -> None: ...
def grid_render(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override; add # ty: ignore[invalid-method-override] on the
override line.
Source code in xnano/grids.py
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
StripRow
¶
Bases: BaseGrid
Signal chart beside the orbit canvas.
Methods:
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_post_init–Called exactly once, when this grid is first attached to a live
-
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_post_init
¶
Called exactly once, when this grid is first attached to a live terminal — after its own hooks are bound, before its first paint.
Unlike __post_init__ (construction time, no terminal attached
yet), ctx/ctx.state are live here. Override with either
signature — the extra parameter is optional, matching every other
@on_* hook, dispatched by arity at runtime (see _call_hook):
def grid_post_init(self) -> None: ...
def grid_post_init(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override (this base declares zero); that's a known false positive
for this flexible-arity hook pattern — add
# ty: ignore[invalid-method-override] on the override line.
Source code in xnano/grids.py
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
RightColumn
¶
Bases: BaseGrid
Wide rail: color palette over the reference deck.
Methods:
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_post_init–Called exactly once, when this grid is first attached to a live
-
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_post_init
¶
Called exactly once, when this grid is first attached to a live terminal — after its own hooks are bound, before its first paint.
Unlike __post_init__ (construction time, no terminal attached
yet), ctx/ctx.state are live here. Override with either
signature — the extra parameter is optional, matching every other
@on_* hook, dispatched by arity at runtime (see _call_hook):
def grid_post_init(self) -> None: ...
def grid_post_init(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override (this base declares zero); that's a known false positive
for this flexible-arity hook pattern — add
# ty: ignore[invalid-method-override] on the override line.
Source code in xnano/grids.py
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
Body
¶
Bases: BaseGrid
The three-column mosaic.
Methods:
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_post_init–Called exactly once, when this grid is first attached to a live
-
grid_render–Called each frame before layout.
-
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_post_init
¶
Called exactly once, when this grid is first attached to a live terminal — after its own hooks are bound, before its first paint.
Unlike __post_init__ (construction time, no terminal attached
yet), ctx/ctx.state are live here. Override with either
signature — the extra parameter is optional, matching every other
@on_* hook, dispatched by arity at runtime (see _call_hook):
def grid_post_init(self) -> None: ...
def grid_post_init(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override (this base declares zero); that's a known false positive
for this flexible-arity hook pattern — add
# ty: ignore[invalid-method-override] on the override line.
Source code in xnano/grids.py
grid_render
¶
Called each frame before layout.
Override to refresh field values every frame. Initial values can be set
with Field(default=...), default_factory, or __post_init__.
Override with either signature — the extra Context parameter is
optional, dispatched by arity like grid_post_init:
def grid_render(self) -> None: ...
def grid_render(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override; add # ty: ignore[invalid-method-override] on the
override line.
Source code in xnano/grids.py
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
Showcase
¶
Bases: BaseGrid
The full showcase: header, the box mosaic, and a keybind legend.
Methods:
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
Demo
¶
Bases: BaseGrid
The full experience: a title splash that gives way to the mosaic.
Methods:
-
grid_get_field_state–Return tracked state for a field.
-
grid_mark_field_dirty–Mark a field as changed.
-
get_field_state–Deprecated alias for
grid_get_field_state. -
mark_field_dirty–Deprecated alias for
grid_mark_field_dirty. -
__post_init__–Called at the end of the generated
__init__. Override to run post-construction logic. -
grid_render–Called each frame before layout.
-
grid_render_extra_small–Refine layout when the viewport is extra small (< 40 cols).
-
grid_render_small–Refine layout when the viewport is small (40–79 cols).
-
grid_render_medium–Refine layout when the viewport is medium (80–119 cols).
-
grid_render_large–Refine layout when the viewport is large (120–159 cols).
-
grid_render_extra_large–Refine layout when the viewport is extra large (>= 160 cols).
-
grid_play_effect–Run a visual effect on one or more layout field areas.
-
grid_effect–Run a visual effect on one or more layout field areas.
-
grid_field_position–Return the parent-relative slide offset for a layout field.
-
grid_set_field–Set a layout field's runtime value and/or per-instance field metadata.
-
grid_update_field–Update a layout field's style/layout attributes, live, in-place.
-
grid_set_frame–Set this grid instance's outer frame (chrome + background fill).
-
grid_set_background–Fill this grid instance's whole area with
background. -
grid_schedule_update–Apply an update on the UI thread before the next frame.
-
set_frame–Deprecated alias for
grid_set_frame. -
set_background–Deprecated alias for
grid_set_background. -
schedule_update–Deprecated alias for
grid_schedule_update.
Attributes:
-
grid_settings(GridSettings) –Class-level grid configuration, like Pydantic's
model_config. -
__xnano_grid__(bool) –Marks this class as a grid, for cheap identity checks.
-
visible(bool) –Whether this grid is rendered in the live session.
-
z(int) –Z-index used when layering overlapping grids.
-
columns(int) –Terminal columns available to this grid — set by the session each frame.
-
rows(int) –Terminal rows available to this grid — set by the session each frame.
-
grid_focused(bool) –Whether any of this grid's fields currently holds field focus.
-
grid_state(Any) –Return the active terminal's shared state, or
None. -
focused(bool) –Deprecated alias for
grid_focused. -
state(Any) –Deprecated alias for
grid_state.
Source code in xnano/grids.py
grid_settings
class-attribute
¶
grid_settings: GridSettings = {}
Class-level grid configuration, like Pydantic's model_config.
__xnano_grid__
class-attribute
¶
__xnano_grid__: bool = True
Marks this class as a grid, for cheap identity checks.
Faster and clearer than duck-typing _grid_fields, and usable from
layers that must not import BaseGrid — see is_grid.
visible
class-attribute
instance-attribute
¶
visible: bool = True
Whether this grid is rendered in the live session.
columns
class-attribute
instance-attribute
¶
columns: int = 0
Terminal columns available to this grid — set by the session each frame.
rows
class-attribute
instance-attribute
¶
rows: int = 0
Terminal rows available to this grid — set by the session each frame.
grid_focused
property
¶
grid_focused: bool
Whether any of this grid's fields currently holds field focus.
Live alongside per-component focused: derived from the same
per-frame focus flags, so self.grid_focused in a hook and
@on_field("focused") both read the current state.
grid_get_field_state
¶
grid_get_field_state(name: str) -> FieldState | None
Return tracked state for a field.
Parameters:
-
name(str) –Field attribute name.
Returns:
-
FieldState | None–Its state, or
Nonefor an unknown field.
Source code in xnano/core/interface.py
grid_mark_field_dirty
¶
grid_mark_field_dirty(name: str) -> None
Mark a field as changed.
Parameters:
-
name(str) –Field attribute name.
Source code in xnano/core/interface.py
get_field_state
¶
get_field_state(name: str) -> FieldState | None
Deprecated alias for grid_get_field_state.
Source code in xnano/core/interface.py
mark_field_dirty
¶
mark_field_dirty(name: str) -> None
Deprecated alias for grid_mark_field_dirty.
Source code in xnano/core/interface.py
__post_init__
¶
grid_render
¶
Called each frame before layout.
Override to refresh field values every frame. Initial values can be set
with Field(default=...), default_factory, or __post_init__.
Override with either signature — the extra Context parameter is
optional, dispatched by arity like grid_post_init:
def grid_render(self) -> None: ...
def grid_render(self, ctx: Context[MyState]) -> None: ...
A static type checker sees the one-parameter form as an invalid
override; add # ty: ignore[invalid-method-override] on the
override line.
Source code in xnano/grids.py
grid_render_extra_small
¶
Refine layout when the viewport is extra small (< 40 cols).
Optional responsive counterpart to :meth:grid_render. Runs when
the window enters this size tier — on the first render and on
later resizes that cross into it — not every frame, so a
per-frame @on_tick mutation is not overwritten by a size hook
resetting the same field. Keep shared per-frame logic in
grid_render and size-specific setup here. Overriding any
grid_render_* variant opts the class into breakpoint dispatch;
a class that overrides none pays no per-frame cost.
Source code in xnano/grids.py
grid_render_small
¶
Refine layout when the viewport is small (40–79 cols).
See :meth:grid_render_extra_small.
grid_render_medium
¶
Refine layout when the viewport is medium (80–119 cols).
See :meth:grid_render_extra_small.
grid_render_large
¶
Refine layout when the viewport is large (120–159 cols).
See :meth:grid_render_extra_small.
grid_render_extra_large
¶
Refine layout when the viewport is extra large (>= 160 cols).
See :meth:grid_render_extra_small.
grid_play_effect
¶
grid_play_effect(
effect: AbstractEffect,
*,
fields: list[str] | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
grid_play_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int = 300,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> bool
Run a visual effect on one or more layout field areas.
Each layout field is tagged with its name as an effect key during
rendering, so effects can target field content rects on the frame
after grid_render.
Pass a custom AbstractEffect subclass or
provide a known effect kind with typed keyword arguments.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int, default:300) –Duration of the effect in milliseconds.
-
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Only meaningful wheneffectis a known-kind string; ignored wheneffectis already a builtAbstractEffectinstance (setkeyon the instance itself in that case).
Returns:
Source code in xnano/grids.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 | |
grid_effect
¶
grid_effect(
effect: KnownEffectKind | AbstractEffect,
*,
duration_ms: int | None = None,
color: ColorLike | None = None,
background: ColorLike | None = None,
direction: EffectMotion | None = None,
gradient_length: int | None = None,
randomness: int | None = None,
interpolation: EffectInterpolation | None = None,
effects: Sequence[AbstractEffect] | None = None,
child: AbstractEffect | None = None,
times: int | None = None,
fields: list[str] | None = None,
key: str | None = None
) -> "EffectHandle"
Run a visual effect on one or more layout field areas.
Returns an EffectHandle: truthy when at least one field was
targeted, with .active and .cancel(), and usable as a
context manager that cancels the effect on exit.
Starting an effect never blocks. duration_ms is the animation
length handed to the renderer, not a sleep — the effect advances
one frame at a time, so hooks keep running while it plays. Omit it
inside a with block and the effect repeats until the block
exits.
Parameters:
-
effect(KnownEffectKind | AbstractEffect) –A built effect instance or a known effect kind string.
-
duration_ms(int | None, default:None) –Animation length in milliseconds. Defaults to 300; omitted inside a
withblock the effect repeats until exit. -
color(ColorLike | None, default:None) –Foreground or accent color for color-driven effects.
-
background(ColorLike | None, default:None) –Background color for two-color effects.
-
direction(EffectMotion | None, default:None) –Motion direction for slide and sweep effects.
-
gradient_length(int | None, default:None) –Gradient length for slide and sweep effects.
-
randomness(int | None, default:None) –Randomness for slide and sweep effects.
-
interpolation(EffectInterpolation | None, default:None) –Interpolation curve for the effect.
-
effects(Sequence[AbstractEffect] | None, default:None) –Child effects for sequence and parallel composition.
-
child(AbstractEffect | None, default:None) –Child effect for repeat and delay composition.
-
times(int | None, default:None) –Repeat count for repeat effects.
-
fields(list[str] | None, default:None) –Layout field names to target. When omitted or empty, no effect is started.
-
key(str | None, default:None) –Identity used to de-duplicate this effect per target field — see
AbstractEffect.key. Calling with the samekeyevery tick replaces the running effect rather than stacking new ones.
Returns:
-
'EffectHandle'–A handle for the started effect.
Examples:
self.grid_effect("fade", fields=["body"])
with self.grid_effect("pulse", fields=["body"]):
do_slow_work()
Source code in xnano/grids.py
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 | |
grid_field_position
¶
grid_set_field
¶
grid_set_field(
name: str,
value: Any = UNSET,
*,
position: tuple[int, int] | None = None,
strict: bool = UNSET,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Set a layout field's runtime value and/or per-instance field metadata.
Cannot be used on state fields. default, default_factory,
init, and state cannot be changed at runtime.
For frequent, value-free style ticks (e.g. from on_tick or an
effect callback), prefer grid_update_field — it skips the
value/position handling this method carries for the general case.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 | |
grid_update_field
¶
grid_update_field(
name: str,
*,
slide: Sequence[Axis] | None = UNSET,
visible: bool | None = UNSET,
wireframe: bool | None = UNSET,
foreground: ColorLike | None = UNSET,
background: ColorLike | None = UNSET,
fill: bool | None = UNSET,
width: SizingLike | None = UNSET,
height: SizingLike | None = UNSET,
gap: int | None = UNSET,
direction: Direction | None = UNSET,
horizontal_align: Alignment | None = UNSET,
vertical_align: VerticalAlignment | None = UNSET,
border: Border | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
border_color: ColorLike | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET,
margin: PaddingLike | None = UNSET,
z: int | None = UNSET,
modifiers: Sequence[CharacterModifier] | None = UNSET,
class_name: ClassNameLike | None = UNSET,
bold: bool = UNSET,
dim: bool = UNSET,
italic: bool = UNSET,
underline: bool = UNSET,
slow_blink: bool = UNSET,
rapid_blink: bool = UNSET,
reversed: bool = UNSET,
color: ColorLike | None = UNSET,
align: Alignment | None = UNSET
) -> None
Update a layout field's style/layout attributes, live, in-place.
A narrower sibling of grid_set_field for frequent, value-free
attribute changes — pulsing a border color from on_tick,
toggling a modifier from an effect callback. It has no value=
or position= parameters at all, so a per-frame style tick never
pays for that method's value-validation branch. Optional style
patches never raise: a missing or state-only name is a no-op
(no try/except needed), though unknown keyword arguments
still raise as a programming error.
color is a deprecated alias for foreground.
Source code in xnano/grids.py
1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 | |
grid_set_frame
¶
grid_set_frame(
frame: Frame | None = UNSET,
*,
background: ColorLike | None = UNSET,
border: Border | None = UNSET,
border_color: ColorLike | None = UNSET,
border_sides: Sequence[Side] | None = UNSET,
title: str | None = UNSET,
title_position: FrameTitlePosition | None = UNSET,
padding: PaddingLike | None = UNSET
) -> None
Set this grid instance's outer frame (chrome + background fill).
The public replacement for mutating the private _grid_frame.
Pass a whole frame to replace it outright, or individual keyword
arguments to patch the current frame in place — a bare
background fills the grid's whole area with no border required,
so nested grids can be themed without any chrome. Pass frame=None
to clear the frame.
Source code in xnano/grids.py
grid_set_background
¶
grid_set_background(background: ColorLike | None) -> None
Fill this grid instance's whole area with background.
Shorthand for grid_set_frame(background=...) — the path for
theming a nested grid, replacing private _grid_frame mutation.
Source code in xnano/grids.py
grid_schedule_update
¶
grid_schedule_update(
callback: Callable[[], Any] | None = None,
*,
field: str | None = None
) -> None
Apply an update on the UI thread before the next frame.
The thread-safe way to reflect background work in the UI: pass a
callback to run on the runtime thread (so it can mutate this grid
without racing the renderer), and/or a field to mark dirty. Safe
to call from any thread; a no-op when no runtime is active.
Source code in xnano/grids.py
set_frame
¶
set_background
¶
set_background(background: ColorLike | None) -> None
Deprecated alias for grid_set_background.
schedule_update
¶
Deprecated alias for grid_schedule_update.
Source code in xnano/grids.py
build_sin_table
¶
Precompute sin(index * frequency + phase) for one axis.
One table per axis keeps per-frame trig at width + height calls rather
than width * height — what makes a full-screen animated canvas
affordable on every rebuild.
Source code in xnano/core/demo.py
build_plasma_frame
¶
build_plasma_frame(
width: int,
height: int,
phase: float,
palette: Sequence[str] = _PLASMA_PALETTE,
) -> CellCanvas
Build an interference-plasma canvas from per-axis sin tables.
Source code in xnano/core/demo.py
build_orbit_frame
¶
build_orbit_frame(
width: int, height: int, phase: float
) -> CellCanvas
Build a Lissajous orbit with a fading trail on a dark field.
Source code in xnano/core/demo.py
build_spiral_frame
¶
build_spiral_frame(
width: int, height: int, phase: float
) -> CellCanvas
Build a rotating Archimedean spiral of glowing points.
Source code in xnano/core/demo.py
build_ripple_frame
¶
build_ripple_frame(
width: int, height: int, phase: float
) -> CellCanvas
Build concentric rings pulsing outward from the center.
Source code in xnano/core/demo.py
build_aurora_frame
¶
build_aurora_frame(
width: int, height: int, phase: float
) -> CellCanvas
Build drifting aurora bands from summed, domain-warped sine layers.
Source code in xnano/core/demo.py
build_ink_frame
¶
build_ink_frame(
width: int, height: int, phase: float
) -> CellCanvas
Build ink-in-water: horizontal drift with vertical bleed, block shades.
Source code in xnano/core/demo.py
build_flow_frame
¶
build_flow_frame(
width: int, height: int, phase: float
) -> CellCanvas
Build a soft diagonal flow field of crossed, domain-warped bands.
Source code in xnano/core/demo.py
build_wordmark_rows
¶
Assemble one word into five rows of block glyphs.
Source code in xnano/core/demo.py
build_title_frame
¶
build_title_frame(
width: int, height: int, phase: float
) -> CellCanvas
Build the splash: an xnano wordmark cut out of a live plasma.
Source code in xnano/core/demo.py
mix_hex
¶
Interpolate two #rrggbb colors.
Source code in xnano/core/demo.py
run_showcase
¶
Run the feature showcase on the live terminal.
Source code in xnano/core/demo.py
run_demo
¶
Run the feature showcase, or view a Markdown document.
Parameters:
-
arguments(Sequence[str] | None, default:None) –Optional command arguments. When the first value is a path, it is opened in the Markdown viewer; otherwise the interactive feature showcase runs.