Skip to content

xnano.core.stage

xnano.core.stage

xnano.core.stage


Expose field layout areas and targeted cell painting for the current frame.

Classes:

  • Stage

    Store named layout areas and frame-local paint requests.

Stage dataclass

Stage(areas: dict[str, Area] = dict())

Store named layout areas and frame-local paint requests.

Example

stage.paint_cell(2, 1, "!", foreground="yellow")

Attributes:

Methods:

  • get_area

    Return the area registered for a name.

  • paint_cell

    Queue one styled cell write for the current frame.

areas class-attribute instance-attribute

areas: dict[str, Area] = dataclasses.field(
    default_factory=dict
)

Areas keyed by field or effect name.

get_area

get_area(name: str) -> Area | None

Return the area registered for a name.

Parameters:

  • name (str) –

    Field or effect name.

Returns:

  • Area | None

    Its area, or None when it has not been laid out.

Source code in xnano/core/stage.py
def get_area(self, name: str) -> Area | None:
    """Return the area registered for a name.

    Args:
        name: Field or effect name.

    Returns:
        Its area, or ``None`` when it has not been laid out.
    """
    return self.areas.get(name)

paint_cell

paint_cell(
    x: int,
    y: int,
    value: str,
    *,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    color: ColorLike | None = None
) -> None

Queue one styled cell write for the current frame.

Parameters:

  • x (int) –

    Cell column.

  • y (int) –

    Cell row.

  • value (str) –

    Character or grapheme to paint.

  • foreground (ColorLike | None, default: None ) –

    Foreground color.

  • background (ColorLike | None, default: None ) –

    Background color.

  • modifiers (Sequence[CharacterModifier] | None, default: None ) –

    Character modifiers.

  • color (ColorLike | None, default: None ) –

    Deprecated alias for foreground.

Source code in xnano/core/stage.py
def paint_cell(
    self,
    x: int,
    y: int,
    value: str,
    *,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    color: ColorLike | None = None,
) -> None:
    """Queue one styled cell write for the current frame.

    Args:
        x: Cell column.
        y: Cell row.
        value: Character or grapheme to paint.
        foreground: Foreground color.
        background: Background color.
        modifiers: Character modifiers.
        color: Deprecated alias for ``foreground``.
    """
    foreground = resolve_color_alias(foreground, color, stacklevel=3)
    self._commands.append(
        {
            "x": x,
            "y": y,
            "value": value,
            "foreground": foreground,
            "background": background,
            "modifiers": tuple(modifiers or ()),
        },
    )