Skip to content

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.

focused property

focused: bool

Whether this component currently holds field focus.

rebuild

rebuild(width: int, height: int) -> None

Rebuild and store the canvas for the current mode and phase.

Source code in xnano/core/demo.py
def rebuild(self, width: int, height: int) -> None:
    """Rebuild and store the canvas for the current mode and phase."""
    self._size = (max(1, width), max(1, height))
    builder = _CANVAS_BUILDERS.get(self.mode, build_plasma_frame)
    self._canvas = builder(*self._size, self.phase)

component_post_init

component_post_init() -> None

Initialize subclass state after dataclass fields are assigned.

Override this method instead of __post_init__.

Source code in xnano/components/component.py
def component_post_init(self) -> None:
    """Initialize subclass state after dataclass fields are assigned.

    Override this method instead of ``__post_init__``.
    """
    return None

get_frame

get_frame() -> Any | None

Optional frame/panel chrome around composed content.

Source code in xnano/components/component.py
def get_frame(self) -> Any | None:
    """Optional frame/panel chrome around composed content."""
    return None

get_size

get_size(ctx: ComponentRenderContext[StateT]) -> Size

Return the preferred cell size of this component.

Source code in xnano/components/component.py
def get_size(self, ctx: ComponentRenderContext[StateT]) -> Size:
    """Return the preferred cell size of this component."""
    return Size(width=0, height=0)

before_render

before_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"

Called before rendering; returns the effective render area.

Source code in xnano/components/component.py
def before_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> "Area":
    """Called before rendering; returns the effective render area."""
    return area

after_render

after_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> None

Called after rendering for optional post-paint work.

Source code in xnano/components/component.py
def after_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> None:
    """Called after rendering for optional post-paint work."""
    return 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
@responsive_noop
def compose_extra_small(
    self, 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.
    """
    return None

compose_small

compose_small(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is small (40–79 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_small(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is small (40–79 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_medium

compose_medium(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is medium (80–119 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_medium(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is medium (80–119 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_large

compose_large(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is large (120–159 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is large (120–159 cols).

    See :meth:`compose_extra_small`.
    """
    return None

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
@responsive_noop
def compose_extra_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is extra large (>= 160 cols).

    See :meth:`compose_extra_small`.
    """
    return None

handle_keyboard

handle_keyboard(keyboard: 'KeyboardEventData') -> bool

Optional keyboard handler while focused.

Returns:

  • bool

    True when the event was consumed.

Source code in xnano/components/component.py
def handle_keyboard(self, keyboard: "KeyboardEventData") -> bool:
    """Optional keyboard handler while focused.

    Returns:
        ``True`` when the event was consumed.
    """
    return False

handle_paste

handle_paste(text: str) -> bool

Optional paste handler while focused.

Returns:

  • bool

    True when the paste was consumed.

Source code in xnano/components/component.py
def handle_paste(self, text: str) -> bool:
    """Optional paste handler while focused.

    Returns:
        ``True`` when the paste was consumed.
    """
    return False

IntroSplash dataclass

IntroSplash(
    phase: float = 0.0,
    *,
    visible: bool = True,
    z: int = 0,
    fit_content: bool = True
)

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.

focused property

focused: bool

Whether this component currently holds field focus.

component_post_init

component_post_init() -> None

Initialize subclass state after dataclass fields are assigned.

Override this method instead of __post_init__.

Source code in xnano/components/component.py
def component_post_init(self) -> None:
    """Initialize subclass state after dataclass fields are assigned.

    Override this method instead of ``__post_init__``.
    """
    return None

get_frame

get_frame() -> Any | None

Optional frame/panel chrome around composed content.

Source code in xnano/components/component.py
def get_frame(self) -> Any | None:
    """Optional frame/panel chrome around composed content."""
    return None

get_size

get_size(ctx: ComponentRenderContext[StateT]) -> Size

Return the preferred cell size of this component.

Source code in xnano/components/component.py
def get_size(self, ctx: ComponentRenderContext[StateT]) -> Size:
    """Return the preferred cell size of this component."""
    return Size(width=0, height=0)

before_render

before_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"

Called before rendering; returns the effective render area.

Source code in xnano/components/component.py
def before_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> "Area":
    """Called before rendering; returns the effective render area."""
    return area

after_render

after_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> None

Called after rendering for optional post-paint work.

Source code in xnano/components/component.py
def after_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> None:
    """Called after rendering for optional post-paint work."""
    return 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
@responsive_noop
def compose_extra_small(
    self, 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.
    """
    return None

compose_small

compose_small(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is small (40–79 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_small(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is small (40–79 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_medium

compose_medium(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is medium (80–119 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_medium(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is medium (80–119 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_large

compose_large(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is large (120–159 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is large (120–159 cols).

    See :meth:`compose_extra_small`.
    """
    return None

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
@responsive_noop
def compose_extra_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is extra large (>= 160 cols).

    See :meth:`compose_extra_small`.
    """
    return None

handle_keyboard

handle_keyboard(keyboard: 'KeyboardEventData') -> bool

Optional keyboard handler while focused.

Returns:

  • bool

    True when the event was consumed.

Source code in xnano/components/component.py
def handle_keyboard(self, keyboard: "KeyboardEventData") -> bool:
    """Optional keyboard handler while focused.

    Returns:
        ``True`` when the event was consumed.
    """
    return False

handle_paste

handle_paste(text: str) -> bool

Optional paste handler while focused.

Returns:

  • bool

    True when the paste was consumed.

Source code in xnano/components/component.py
def handle_paste(self, text: str) -> bool:
    """Optional paste handler while focused.

    Returns:
        ``True`` when the paste was consumed.
    """
    return False

MetricsPanel dataclass

MetricsPanel(
    *,
    visible: bool = True,
    z: int = 0,
    fit_content: bool = True
)

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.

focused property

focused: bool

Whether this component currently holds field focus.

component_post_init

component_post_init() -> None

Initialize subclass state after dataclass fields are assigned.

Override this method instead of __post_init__.

Source code in xnano/components/component.py
def component_post_init(self) -> None:
    """Initialize subclass state after dataclass fields are assigned.

    Override this method instead of ``__post_init__``.
    """
    return None

get_frame

get_frame() -> Any | None

Optional frame/panel chrome around composed content.

Source code in xnano/components/component.py
def get_frame(self) -> Any | None:
    """Optional frame/panel chrome around composed content."""
    return None

get_size

get_size(ctx: ComponentRenderContext[StateT]) -> Size

Return the preferred cell size of this component.

Source code in xnano/components/component.py
def get_size(self, ctx: ComponentRenderContext[StateT]) -> Size:
    """Return the preferred cell size of this component."""
    return Size(width=0, height=0)

before_render

before_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"

Called before rendering; returns the effective render area.

Source code in xnano/components/component.py
def before_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> "Area":
    """Called before rendering; returns the effective render area."""
    return area

after_render

after_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> None

Called after rendering for optional post-paint work.

Source code in xnano/components/component.py
def after_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> None:
    """Called after rendering for optional post-paint work."""
    return 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
@responsive_noop
def compose_extra_small(
    self, 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.
    """
    return None

compose_small

compose_small(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is small (40–79 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_small(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is small (40–79 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_medium

compose_medium(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is medium (80–119 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_medium(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is medium (80–119 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_large

compose_large(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is large (120–159 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is large (120–159 cols).

    See :meth:`compose_extra_small`.
    """
    return None

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
@responsive_noop
def compose_extra_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is extra large (>= 160 cols).

    See :meth:`compose_extra_small`.
    """
    return None

handle_keyboard

handle_keyboard(keyboard: 'KeyboardEventData') -> bool

Optional keyboard handler while focused.

Returns:

  • bool

    True when the event was consumed.

Source code in xnano/components/component.py
def handle_keyboard(self, keyboard: "KeyboardEventData") -> bool:
    """Optional keyboard handler while focused.

    Returns:
        ``True`` when the event was consumed.
    """
    return False

handle_paste

handle_paste(text: str) -> bool

Optional paste handler while focused.

Returns:

  • bool

    True when the paste was consumed.

Source code in xnano/components/component.py
def handle_paste(self, text: str) -> bool:
    """Optional paste handler while focused.

    Returns:
        ``True`` when the paste was consumed.
    """
    return False

StageBox

StageBox()

Bases: BaseGrid

The large center stage: an animated canvas with three inner tabs.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_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
def select_tab(self, index: int) -> None:
    """Set the stage animation mode and force an immediate rebuild."""
    self.tab_index = index % len(_STAGE_MODES)
    self.view.mode = _STAGE_MODES[self.tab_index]
    self.view.rebuild(max(1, self.columns), max(1, self.rows))

cycle_tab

cycle_tab(delta: int) -> None

Switch the stage animation mode by delta tabs.

Source code in xnano/core/demo.py
def cycle_tab(self, delta: int) -> None:
    """Switch the stage animation mode by ``delta`` tabs."""
    self.select_tab(self.tab_index + delta)

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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_post_init

grid_post_init() -> None

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
def grid_post_init(self) -> None:
    """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.
    """

grid_render

grid_render() -> None

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
def grid_render(self) -> None:
    """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.
    """

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

OrbitBox

OrbitBox()

Bases: BaseGrid

A drifting canvas with three motion tabs of its own.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_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
def select_tab(self, index: int) -> None:
    """Set the orbit motion pattern and force an immediate rebuild."""
    self.tab_index = index % len(_ORBIT_MODES)
    self.view.mode = _ORBIT_MODES[self.tab_index]
    self.view.rebuild(max(1, self.columns), max(1, self.rows))

cycle_tab

cycle_tab(delta: int) -> None

Rotate the orbit motion pattern by delta tabs.

Source code in xnano/core/demo.py
def cycle_tab(self, delta: int) -> None:
    """Rotate the orbit motion pattern by ``delta`` tabs."""
    self.select_tab(self.tab_index + delta)

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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_post_init

grid_post_init() -> None

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
def grid_post_init(self) -> None:
    """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.
    """

grid_render

grid_render() -> None

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
def grid_render(self) -> None:
    """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.
    """

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

SignalBox

SignalBox()

Bases: BaseGrid

Live signal box with Wave, Bars, and Spark inner tabs.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_state.

select_tab

select_tab(index: int) -> None

Select the wave, bar, or spark view by tab index.

Source code in xnano/core/demo.py
def select_tab(self, index: int) -> None:
    """Select the wave, bar, or spark view by tab index."""
    self.tab_index = index % len(self._TABS)

cycle_tab

cycle_tab(delta: int) -> None

Rotate through the signal views.

Source code in xnano/core/demo.py
def cycle_tab(self, delta: int) -> None:
    """Rotate through the signal views."""
    self.select_tab(self.tab_index + delta)

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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

PalettePanel dataclass

PalettePanel(
    *,
    visible: bool = True,
    z: int = 0,
    fit_content: bool = True
)

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.

focused property

focused: bool

Whether this component currently holds field focus.

component_post_init

component_post_init() -> None

Initialize subclass state after dataclass fields are assigned.

Override this method instead of __post_init__.

Source code in xnano/components/component.py
def component_post_init(self) -> None:
    """Initialize subclass state after dataclass fields are assigned.

    Override this method instead of ``__post_init__``.
    """
    return None

get_frame

get_frame() -> Any | None

Optional frame/panel chrome around composed content.

Source code in xnano/components/component.py
def get_frame(self) -> Any | None:
    """Optional frame/panel chrome around composed content."""
    return None

get_size

get_size(ctx: ComponentRenderContext[StateT]) -> Size

Return the preferred cell size of this component.

Source code in xnano/components/component.py
def get_size(self, ctx: ComponentRenderContext[StateT]) -> Size:
    """Return the preferred cell size of this component."""
    return Size(width=0, height=0)

before_render

before_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> "Area"

Called before rendering; returns the effective render area.

Source code in xnano/components/component.py
def before_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> "Area":
    """Called before rendering; returns the effective render area."""
    return area

after_render

after_render(
    ctx: ComponentRenderContext[StateT], area: "Area"
) -> None

Called after rendering for optional post-paint work.

Source code in xnano/components/component.py
def after_render(
    self,
    ctx: ComponentRenderContext[StateT],
    area: "Area",
) -> None:
    """Called after rendering for optional post-paint work."""
    return 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
@responsive_noop
def compose_extra_small(
    self, 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.
    """
    return None

compose_small

compose_small(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is small (40–79 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_small(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is small (40–79 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_medium

compose_medium(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is medium (80–119 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_medium(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is medium (80–119 cols).

    See :meth:`compose_extra_small`.
    """
    return None

compose_large

compose_large(
    ctx: ComponentRenderContext[StateT],
) -> Content | None

Compose content when the viewport is large (120–159 cols).

See :meth:compose_extra_small.

Source code in xnano/components/component.py
@responsive_noop
def compose_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is large (120–159 cols).

    See :meth:`compose_extra_small`.
    """
    return None

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
@responsive_noop
def compose_extra_large(
    self, ctx: ComponentRenderContext[StateT]
) -> Content | None:
    """Compose content when the viewport is extra large (>= 160 cols).

    See :meth:`compose_extra_small`.
    """
    return None

handle_keyboard

handle_keyboard(keyboard: 'KeyboardEventData') -> bool

Optional keyboard handler while focused.

Returns:

  • bool

    True when the event was consumed.

Source code in xnano/components/component.py
def handle_keyboard(self, keyboard: "KeyboardEventData") -> bool:
    """Optional keyboard handler while focused.

    Returns:
        ``True`` when the event was consumed.
    """
    return False

handle_paste

handle_paste(text: str) -> bool

Optional paste handler while focused.

Returns:

  • bool

    True when the paste was consumed.

Source code in xnano/components/component.py
def handle_paste(self, text: str) -> bool:
    """Optional paste handler while focused.

    Returns:
        ``True`` when the paste was consumed.
    """
    return False

DeckBox

DeckBox()

Bases: BaseGrid

A three-tab reference deck: overview text, a table, and code.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_state.

select_tab

select_tab(index: int) -> None

Select a deck tab by index.

Source code in xnano/core/demo.py
def select_tab(self, index: int) -> None:
    """Select a deck tab by index."""
    self.tab_index = index % len(_DECK_TABS)

cycle_tab

cycle_tab(delta: int) -> None

Rotate through the deck tabs.

Source code in xnano/core/demo.py
def cycle_tab(self, delta: int) -> None:
    """Rotate through the deck tabs."""
    self.select_tab(self.tab_index + delta)

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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_post_init

grid_post_init() -> None

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
def grid_post_init(self) -> None:
    """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.
    """

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

LogBox

LogBox()

Bases: BaseGrid

A rolling event log, appended to as keybinds fire.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_state.

append

append(message: str) -> None

Record one event line.

Source code in xnano/core/demo.py
def append(self, message: str) -> None:
    """Record one event line."""
    self._lines = (self._lines + [message])[-40:]

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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

LeftColumn

LeftColumn()

Bases: BaseGrid

Narrow rail: metrics over the event log.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_post_init

grid_post_init() -> None

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
def grid_post_init(self) -> None:
    """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.
    """

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

CenterColumn

CenterColumn()

Bases: BaseGrid

The main column: the stage over a signal/orbit strip.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_post_init

grid_post_init() -> None

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
def grid_post_init(self) -> None:
    """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.
    """

grid_render

grid_render() -> None

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
def grid_render(self) -> None:
    """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.
    """

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

StripRow

StripRow()

Bases: BaseGrid

Signal chart beside the orbit canvas.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_post_init

grid_post_init() -> None

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
def grid_post_init(self) -> None:
    """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.
    """

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

RightColumn

RightColumn()

Bases: BaseGrid

Wide rail: color palette over the reference deck.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_post_init

grid_post_init() -> None

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
def grid_post_init(self) -> None:
    """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.
    """

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

Body

Body()

Bases: BaseGrid

The three-column mosaic.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_post_init

grid_post_init() -> None

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
def grid_post_init(self) -> None:
    """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.
    """

grid_render

grid_render() -> None

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
def grid_render(self) -> None:
    """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.
    """

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

Showcase

Showcase()

Bases: BaseGrid

The full showcase: header, the box mosaic, and a keybind legend.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

Demo

Demo()

Bases: BaseGrid

The full experience: a title splash that gives way to the mosaic.

Methods:

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
def __init__(self) -> None:
    self._grid_init_field_states()
    self.__post_init__()

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.

z class-attribute instance-attribute

z: int = 0

Z-index used when layering overlapping grids.

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_state property

grid_state: Any

Return the active terminal's shared state, or None.

focused property

focused: bool

Deprecated alias for grid_focused.

state property

state: Any

Deprecated alias for grid_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 None for an unknown field.

Source code in xnano/core/interface.py
def grid_get_field_state(self, name: str) -> FieldState | None:
    """Return tracked state for a field.

    Args:
        name: Field attribute name.

    Returns:
        Its state, or ``None`` for an unknown field.
    """
    return getattr(self, "_grid_field_states", {}).get(name)

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
def grid_mark_field_dirty(self, name: str) -> None:
    """Mark a field as changed.

    Args:
        name: Field attribute name.
    """
    state = self.grid_get_field_state(name)
    if state is not None:
        state.mark_dirty()
        state.value = getattr(self, name, None)

get_field_state

get_field_state(name: str) -> FieldState | None

Deprecated alias for grid_get_field_state.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.get_field_state",
    "AbstractInterface.grid_get_field_state",
)
def get_field_state(self, name: str) -> FieldState | None:
    """Deprecated alias for ``grid_get_field_state``."""
    return self.grid_get_field_state(name)

mark_field_dirty

mark_field_dirty(name: str) -> None

Deprecated alias for grid_mark_field_dirty.

Source code in xnano/core/interface.py
@warn_renamed_attribute(
    "AbstractInterface.mark_field_dirty",
    "AbstractInterface.grid_mark_field_dirty",
)
def mark_field_dirty(self, name: str) -> None:
    """Deprecated alias for ``grid_mark_field_dirty``."""
    self.grid_mark_field_dirty(name)

__post_init__

__post_init__() -> None

Called at the end of the generated __init__. Override to run post-construction logic.

Source code in xnano/grids.py
def __post_init__(self) -> None:
    """Called at the end of the generated ``__init__``. Override to run post-construction logic."""

grid_render

grid_render() -> None

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
def grid_render(self) -> None:
    """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.
    """

grid_render_extra_small

grid_render_extra_small() -> None

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
@responsive_noop
def grid_render_extra_small(self) -> None:
    """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.
    """

grid_render_small

grid_render_small() -> None

Refine layout when the viewport is small (40–79 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_small(self) -> None:
    """Refine layout when the viewport is small (40–79 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_medium

grid_render_medium() -> None

Refine layout when the viewport is medium (80–119 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_medium(self) -> None:
    """Refine layout when the viewport is medium (80–119 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_large

grid_render_large() -> None

Refine layout when the viewport is large (120–159 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_large(self) -> None:
    """Refine layout when the viewport is large (120–159 cols).

    See :meth:`grid_render_extra_small`.
    """

grid_render_extra_large

grid_render_extra_large() -> None

Refine layout when the viewport is extra large (>= 160 cols).

See :meth:grid_render_extra_small.

Source code in xnano/grids.py
@responsive_noop
def grid_render_extra_large(self) -> None:
    """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 when effect is a known-kind string; ignored when effect is already a built AbstractEffect instance (set key on the instance itself in that case).

Returns:

  • bool

    True when at least one field area was found and an effect

  • bool

    started.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.grid_play_effect", "BaseGrid.grid_effect"
)
def grid_play_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Duration of the effect in milliseconds.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty, no
            effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Only meaningful when
            ``effect`` is a known-kind string; ignored when ``effect``
            is already a built ``AbstractEffect`` instance (set
            ``key`` on the instance itself in that case).

    Returns:
        ``True`` when at least one field area was found and an effect
        started.
    """
    return bool(
        self.grid_effect(
            effect,
            duration_ms=duration_ms,
            color=color,
            background=background,
            direction=direction,
            gradient_length=gradient_length,
            randomness=randomness,
            interpolation=interpolation,
            effects=effects,
            child=child,
            times=times,
            fields=fields,
            key=key,
        )
    )

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 with block 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 same key every 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
def grid_effect(
    self,
    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.

    Args:
        effect: A built effect instance or a known effect kind string.
        duration_ms: Animation length in milliseconds. Defaults to
            300; omitted inside a ``with`` block the effect repeats
            until exit.
        color: Foreground or accent color for color-driven effects.
        background: Background color for two-color effects.
        direction: Motion direction for slide and sweep effects.
        gradient_length: Gradient length for slide and sweep effects.
        randomness: Randomness for slide and sweep effects.
        interpolation: Interpolation curve for the effect.
        effects: Child effects for sequence and parallel composition.
        child: Child effect for repeat and delay composition.
        times: Repeat count for repeat effects.
        fields: Layout field names to target. When omitted or empty,
            no effect is started.
        key: Identity used to de-duplicate this effect per target
            field — see ``AbstractEffect.key``. Calling with the same
            ``key`` every tick replaces the running effect rather than
            stacking new ones.

    Returns:
        A handle for the started effect.

    Examples:
        ```python
        self.grid_effect("fade", fields=["body"])

        with self.grid_effect("pulse", fields=["body"]):
            do_slow_work()
        ```
    """
    from xnano.core.runtime import get_active_runtime
    from xnano.effects import EffectHandle, resolve_effect

    runtime = get_active_runtime()
    if runtime is None:
        return EffectHandle()
    resolved_effect = resolve_effect(
        effect,
        duration_ms=300 if duration_ms is None else duration_ms,
        color=color,
        background=background,
        direction=direction,
        gradient_length=gradient_length,
        randomness=randomness,
        interpolation=interpolation,
        effects=effects,
        child=child,
        times=times,
        key=key,
    )
    keys = runtime.play_effect(resolved_effect, fields=fields)
    return EffectHandle(
        keys=tuple(keys),
        runtime=runtime,
        effect=resolved_effect,
        fields=tuple(fields or ()),
        loop_in_context=duration_ms is None,
    )

grid_field_position

grid_field_position(name: str) -> tuple[int, int]

Return the parent-relative slide offset for a layout field.

Source code in xnano/grids.py
def grid_field_position(self, name: str) -> tuple[int, int]:
    """Return the parent-relative slide offset for a layout field."""
    return self._grid_field_position(name)

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
def grid_set_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "strict": strict,
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }

    self._grid_apply_field_config(
        name, field_config, caller="grid_set_field"
    )

    if position is not None:
        slot = getattr(self, "_grid_last_slot_areas", {}).get(name)
        parent = getattr(self, "_grid_last_parent_area", None)
        if slot is not None and parent is not None:
            self._grid_set_field_position(
                name,
                position,
                parent_area=parent,
                slot_area=slot,
            )
        else:
            self.__dict__.setdefault("_grid_field_positions", {})[name] = (
                position
            )

    if value is not UNSET:
        field = self._grid_field_info(name)
        if self._grid_strict:
            value = self._grid_validate_field(name, value, field=field)
        object.__setattr__(self, name, value)

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
def grid_update_field(
    self,
    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``.
    """
    foreground = resolve_color_alias(
        foreground, color, unset=UNSET, stacklevel=3
    )
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        unset=UNSET,
        stacklevel=3,
    )
    field_config: dict[str, Any] = {
        key: option
        for key, option in {
            "slide": slide,
            "visible": visible,
            "wireframe": wireframe,
            "foreground": foreground,
            "background": background,
            "fill": fill,
            "width": width,
            "height": height,
            "gap": gap,
            "direction": direction,
            "horizontal_align": horizontal_align,
            "vertical_align": vertical_align,
            "border": border,
            "border_sides": border_sides,
            "border_color": border_color,
            "title": title,
            "title_position": title_position,
            "padding": padding,
            "margin": margin,
            "z": z,
            "modifiers": modifiers,
            "class_name": class_name,
            "bold": bold,
            "dim": dim,
            "italic": italic,
            "underline": underline,
            "slow_blink": slow_blink,
            "rapid_blink": rapid_blink,
            "reversed": reversed,
        }.items()
        if option is not UNSET
    }
    self._grid_apply_field_config(
        name, field_config, caller="grid_update_field", missing="ignore"
    )

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
def grid_set_frame(
    self,
    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.
    """
    if frame is not UNSET:
        object.__setattr__(
            self, "_grid_frame", None if frame is None else frame
        )
        return
    current = getattr(self, "_grid_frame", None) or Frame()
    patch = {
        key: value
        for key, value in {
            "background": background,
            "border": border,
            "border_color": border_color,
            "border_sides": border_sides,
            "title": title,
            "title_position": title_position,
            "padding": padding,
        }.items()
        if value is not UNSET
    }
    if not patch:
        return
    updated = dataclasses.replace(current, **patch)
    object.__setattr__(
        self, "_grid_frame", None if updated.is_empty() else updated
    )

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
def grid_set_background(self, 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.
    """
    self.grid_set_frame(background=background)

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
def grid_schedule_update(
    self,
    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.
    """
    from xnano.core.runtime import get_active_runtime

    runtime = get_active_runtime()

    def _apply() -> None:
        if callback is not None:
            callback()
        if field is not None:
            self.grid_mark_field_dirty(field)

    if runtime is None:
        _apply()
    else:
        runtime.call_soon(_apply)

set_frame

set_frame(*args: Any, **kwargs: Any) -> None

Deprecated alias for grid_set_frame.

Source code in xnano/grids.py
@warn_renamed_attribute("BaseGrid.set_frame", "BaseGrid.grid_set_frame")
def set_frame(self, *args: Any, **kwargs: Any) -> None:
    """Deprecated alias for ``grid_set_frame``."""
    self.grid_set_frame(*args, **kwargs)

set_background

set_background(background: ColorLike | None) -> None

Deprecated alias for grid_set_background.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.set_background", "BaseGrid.grid_set_background"
)
def set_background(self, background: ColorLike | None) -> None:
    """Deprecated alias for ``grid_set_background``."""
    self.grid_set_background(background)

schedule_update

schedule_update(
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None
) -> None

Deprecated alias for grid_schedule_update.

Source code in xnano/grids.py
@warn_renamed_attribute(
    "BaseGrid.schedule_update", "BaseGrid.grid_schedule_update"
)
def schedule_update(
    self,
    callback: Callable[[], Any] | None = None,
    *,
    field: str | None = None,
) -> None:
    """Deprecated alias for ``grid_schedule_update``."""
    self.grid_schedule_update(callback, field=field)

build_sin_table

build_sin_table(
    count: int, frequency: float, phase: float
) -> list[float]

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
def build_sin_table(
    count: int,
    frequency: float,
    phase: float,
) -> list[float]:
    """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.
    """
    return [math.sin(index * frequency + phase) for index in range(count)]

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
def 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."""
    width = max(1, width)
    height = max(1, height)
    column_wave = build_sin_table(width, 0.18, phase)
    row_wave = build_sin_table(height, 0.32, -phase * 0.7)
    glyphs = " ░▒▓█"
    drift = int(phase * 4)
    palette_length = len(palette)
    rows: list[tuple[CellSpan, ...]] = []
    for row_index in range(height):
        vertical = row_wave[row_index]
        spans: list[CellSpan] = []
        for column_index in range(width):
            energy = column_wave[column_index] + vertical
            level = min(4, max(0, int((energy + 2.0) * 1.25)))
            color = palette[
                (column_index + row_index + drift) % palette_length
            ]
            spans.append(CellSpan(text=glyphs[level], foreground=color))
        rows.append(tuple(spans))
    return CellCanvas(rows=tuple(rows), width=width, height=height)

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
def build_orbit_frame(
    width: int,
    height: int,
    phase: float,
) -> CellCanvas:
    """Build a Lissajous orbit with a fading trail on a dark field."""
    width = max(1, width)
    height = max(1, height)
    grid: list[list[int]] = [[-1] * width for _ in range(height)]
    trail_length = len(_ORBIT_TRAIL)
    samples = 26
    for step in range(samples):
        theta = phase - step * 0.16
        x_norm = 0.5 + 0.42 * math.sin(theta * 1.0)
        y_norm = 0.5 + 0.42 * math.sin(theta * 1.4 + 1.2)
        column = min(width - 1, max(0, int(x_norm * (width - 1))))
        row = min(height - 1, max(0, int(y_norm * (height - 1))))
        intensity = trail_length - 1 - min(trail_length - 1, step // 5)
        if intensity > grid[row][column]:
            grid[row][column] = intensity
    rows: list[tuple[CellSpan, ...]] = []
    for row_index in range(height):
        spans: list[CellSpan] = []
        for column_index in range(width):
            level = grid[row_index][column_index]
            if level < 0:
                spans.append(CellSpan(text="·", foreground="#182234"))
            else:
                glyph = "●" if level >= trail_length - 1 else "•"
                spans.append(
                    CellSpan(text=glyph, foreground=_ORBIT_TRAIL[level])
                )
        rows.append(tuple(spans))
    return CellCanvas(rows=tuple(rows), width=width, height=height)

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
def build_spiral_frame(
    width: int,
    height: int,
    phase: float,
) -> CellCanvas:
    """Build a rotating Archimedean spiral of glowing points."""
    width = max(1, width)
    height = max(1, height)
    grid: list[list[int]] = [[-1] * width for _ in range(height)]
    trail_length = len(_ORBIT_TRAIL)
    center_x = (width - 1) / 2
    center_y = (height - 1) / 2
    for step in range(60):
        angle = step * 0.5 + phase
        radius = step * 0.08
        column = int(center_x + math.cos(angle) * radius * center_x * 0.9)
        row = int(center_y + math.sin(angle) * radius * center_y * 0.9)
        if 0 <= column < width and 0 <= row < height:
            level = trail_length - 1 - min(trail_length - 1, step // 12)
            grid[row][column] = max(grid[row][column], level)
    rows: list[tuple[CellSpan, ...]] = []
    for row_index in range(height):
        spans: list[CellSpan] = []
        for column_index in range(width):
            level = grid[row_index][column_index]
            if level < 0:
                spans.append(CellSpan(text="·", foreground="#182234"))
            else:
                spans.append(
                    CellSpan(text="✦", foreground=_ORBIT_TRAIL[level])
                )
        rows.append(tuple(spans))
    return CellCanvas(rows=tuple(rows), width=width, height=height)

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
def build_ripple_frame(
    width: int,
    height: int,
    phase: float,
) -> CellCanvas:
    """Build concentric rings pulsing outward from the center."""
    width = max(1, width)
    height = max(1, height)
    ramp = _ORBIT_TRAIL
    ramp_length = len(ramp)
    center_x = (width - 1) / 2
    center_y = (height - 1) / 2
    glyphs = " ·∘○●"
    rows: list[tuple[CellSpan, ...]] = []
    for row_index in range(height):
        dy = (row_index - center_y) * 2.0
        spans: list[CellSpan] = []
        for column_index in range(width):
            dx = column_index - center_x
            distance = math.sqrt(dx * dx + dy * dy)
            wave = math.sin(distance * 0.6 - phase * 1.5)
            level = int((wave + 1.0) * 2.0)
            level = min(ramp_length - 1, max(0, level))
            spans.append(CellSpan(text=glyphs[level], foreground=ramp[level]))
        rows.append(tuple(spans))
    return CellCanvas(rows=tuple(rows), width=width, height=height)

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
def build_aurora_frame(
    width: int,
    height: int,
    phase: float,
) -> CellCanvas:
    """Build drifting aurora bands from summed, domain-warped sine layers."""
    width = max(1, width)
    height = max(1, height)
    ramp = _TWILIGHT
    top = len(ramp) - 1
    glyphs = " ░▒▓█"
    column_slow = [math.sin(x * 0.11 + phase * 1.3) for x in range(width)]
    column_fine = [math.sin(x * 0.045 - phase * 0.7) for x in range(width)]
    row_slow = [math.sin(y * 0.5 - phase * 1.1) for y in range(height)]
    row_fine = [math.cos(y * 0.19 + phase * 0.5) for y in range(height)]
    rows: list[tuple[CellSpan, ...]] = []
    for row_index in range(height):
        vertical = row_slow[row_index]
        drift = row_fine[row_index]
        spans: list[CellSpan] = []
        for column_index in range(width):
            warp = column_fine[column_index] * 1.4
            energy = column_slow[column_index] + vertical + drift * 0.6 + warp
            index = int((energy + 3.0) * (top / 6.0))
            if index < 0:
                index = 0
            elif index > top:
                index = top
            glyph = glyphs[min(4, index * 5 // (top + 1))]
            spans.append(CellSpan(text=glyph, foreground=ramp[index]))
        rows.append(tuple(spans))
    return CellCanvas(rows=tuple(rows), width=width, height=height)

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
def build_ink_frame(
    width: int,
    height: int,
    phase: float,
) -> CellCanvas:
    """Build ink-in-water: horizontal drift with vertical bleed, block shades."""
    width = max(1, width)
    height = max(1, height)
    ramp = _TWILIGHT
    top = len(ramp) - 1
    glyphs = " ▁▂▃▄▅▆▇█"
    glyph_top = len(glyphs) - 1
    column_slow = [math.sin(x * 0.16 + phase) for x in range(width)]
    column_fine = [math.cos(x * 0.07 - phase * 0.55) for x in range(width)]
    row_slow = [math.sin(y * 0.28 - phase * 0.9) for y in range(height)]
    row_bleed = [math.sin(y * 0.09 + phase * 0.4) for y in range(height)]
    rows: list[tuple[CellSpan, ...]] = []
    for row_index in range(height):
        vertical = row_slow[row_index]
        bleed = row_bleed[row_index]
        spans: list[CellSpan] = []
        for column_index in range(width):
            value = column_slow[column_index] * (0.6 + 0.4 * bleed)
            value += column_fine[column_index] * vertical + vertical * 0.5
            norm = (value + 2.2) / 4.4
            if norm < 0.0:
                norm = 0.0
            elif norm > 1.0:
                norm = 1.0
            index = int(norm * top)
            glyph = glyphs[int(norm * glyph_top)]
            foreground = ramp[min(top, index + 2)]
            spans.append(
                CellSpan(
                    text=glyph, foreground=foreground, background=ramp[index]
                )
            )
        rows.append(tuple(spans))
    return CellCanvas(rows=tuple(rows), width=width, height=height)

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
def build_flow_frame(
    width: int,
    height: int,
    phase: float,
) -> CellCanvas:
    """Build a soft diagonal flow field of crossed, domain-warped bands."""
    width = max(1, width)
    height = max(1, height)
    ramp = _TWILIGHT
    top = len(ramp) - 1
    glyphs = " ·∘○●"
    column_slow = [math.sin(x * 0.13 + phase * 0.9) for x in range(width)]
    column_fine = [math.sin(x * 0.31 - phase * 1.4) for x in range(width)]
    row_slow = [math.sin(y * 0.21 + phase * 1.2) for y in range(height)]
    row_fine = [math.cos(y * 0.4 - phase * 0.6) for y in range(height)]
    rows: list[tuple[CellSpan, ...]] = []
    for row_index in range(height):
        vertical = row_slow[row_index]
        warp_axis = row_fine[row_index]
        spans: list[CellSpan] = []
        for column_index in range(width):
            warped = column_fine[column_index] * warp_axis
            value = column_slow[column_index] + vertical + warped * 1.3
            norm = (value + 3.3) / 6.6
            if norm < 0.0:
                norm = 0.0
            elif norm > 1.0:
                norm = 1.0
            index = int(norm * top)
            glyph = glyphs[min(4, int(norm * 5))]
            spans.append(
                CellSpan(
                    text=glyph,
                    foreground=ramp[index],
                    background=ramp[max(0, index - 3)],
                )
            )
        rows.append(tuple(spans))
    return CellCanvas(rows=tuple(rows), width=width, height=height)

build_wordmark_rows

build_wordmark_rows(word: str) -> list[str]

Assemble one word into five rows of block glyphs.

Source code in xnano/core/demo.py
def build_wordmark_rows(word: str) -> list[str]:
    """Assemble one word into five rows of block glyphs."""
    rows = ["", "", "", "", ""]
    blank = ("     ",) * 5
    for character in word:
        pattern = _LETTER_ROWS.get(character, blank)
        for index in range(5):
            rows[index] += pattern[index] + " "
    return [row.rstrip() for row in rows]

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
def build_title_frame(
    width: int,
    height: int,
    phase: float,
) -> CellCanvas:
    """Build the splash: an ``xnano`` wordmark cut out of a live plasma."""
    width = max(1, width)
    height = max(1, height)
    base = build_plasma_frame(width, height, phase)
    rows = [list(row) for row in base.rows]
    mark_width = max((len(line) for line in _WORDMARK), default=0)
    left = max(0, (width - mark_width) // 2)
    top = max(0, height // 2 - 4)
    glow = mix_hex("#d8bfa8", "#f0e6dc", 0.5 + 0.5 * math.sin(phase * 2))
    for line_index, line in enumerate(_WORDMARK):
        target = top + line_index
        if not 0 <= target < height:
            continue
        for column_offset, character in enumerate(line):
            column = left + column_offset
            if character != " " and 0 <= column < width:
                rows[target][column] = CellSpan(
                    text="█", foreground=glow, modifiers=("bold",)
                )
    _overlay_centered(
        rows, width, height - 2, "press any key to begin", "#9a9ac0"
    )
    return CellCanvas(
        rows=tuple(tuple(row) for row in rows),
        width=width,
        height=height,
    )

mix_hex

mix_hex(start: str, end: str, ratio: float) -> str

Interpolate two #rrggbb colors.

Source code in xnano/core/demo.py
def mix_hex(start: str, end: str, ratio: float) -> str:
    """Interpolate two ``#rrggbb`` colors."""
    start_rgb = (
        int(start[1:3], 16),
        int(start[3:5], 16),
        int(start[5:7], 16),
    )
    end_rgb = (int(end[1:3], 16), int(end[3:5], 16), int(end[5:7], 16))
    mixed = tuple(
        round(a + (b - a) * ratio) for a, b in zip(start_rgb, end_rgb)
    )
    return f"#{mixed[0]:02x}{mixed[1]:02x}{mixed[2]:02x}"

run_showcase

run_showcase() -> None

Run the feature showcase on the live terminal.

Source code in xnano/core/demo.py
def run_showcase() -> None:
    """Run the feature showcase on the live terminal."""
    import shutil

    from xnano.terminal import Terminal

    width, height = shutil.get_terminal_size(fallback=(120, 40))
    interval = _paint_interval_ms(width, height)
    Terminal(title="xnano · showcase", tick_interval=interval).run(Demo())

run_demo

run_demo(arguments: Sequence[str] | None = None) -> None

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.

Source code in xnano/core/demo.py
def run_demo(arguments: Sequence[str] | None = None) -> None:
    """Run the feature showcase, or view a Markdown document.

    Args:
        arguments: Optional command arguments. When the first value is a
            path, it is opened in the Markdown viewer; otherwise the
            interactive feature showcase runs.
    """
    values = list(arguments or ())
    if values:
        from xnano.markdown import run_markdown

        run_markdown(pathlib.Path(values[0]))
        return
    run_showcase()