Skip to content

xnano.effects

xnano.effects

xnano.effects


Animate grid fields with fades, movement, painting, delays, and composition.

Classes:

Functions:

  • resolve_effect

    Resolve an effect description into an AbstractEffect.

  • Effect

    Create a user-facing effect description.

Attributes:

EffectMotion module-attribute

EffectMotion: TypeAlias = Literal[
    "up_to_down",
    "down_to_up",
    "left_to_right",
    "right_to_left",
]

Directional motion for slide and sweep effects.

Values

"up_to_down": Motion travels from the top edge downward. "down_to_up": Motion travels from the bottom edge upward. "left_to_right": Motion travels from the left edge rightward. "right_to_left": Motion travels from the right edge leftward.

EffectInterpolation module-attribute

EffectInterpolation: TypeAlias = Literal[
    "linear",
    "smooth_step",
    "sine_in",
    "sine_out",
    "sine_in_out",
    "quad_in",
    "quad_out",
    "quad_in_out",
    "cubic_in",
    "cubic_out",
    "cubic_in_out",
    "expo_in",
    "expo_out",
    "expo_in_out",
    "bounce_in",
    "bounce_out",
    "bounce_in_out",
    "elastic_in",
    "elastic_out",
    "elastic_in_out",
    "back_in",
    "back_out",
    "back_in_out",
    "spring",
]

Interpolation curve applied over an effect's duration.

Values

"linear": Constant-rate progression. "smooth_step": Eased start and end with a smooth midpoint. "sine_in" / "sine_out" / "sine_in_out": Sinusoidal easing. "quad_in" / "quad_out" / "quad_in_out": Quadratic easing. "cubic_in" / "cubic_out" / "cubic_in_out": Cubic easing. "expo_in" / "expo_out" / "expo_in_out": Exponential easing. "bounce_in" / "bounce_out" / "bounce_in_out": Bounce easing. "elastic_in" / "elastic_out" / "elastic_in_out": Elastic easing. "back_in" / "back_out" / "back_in_out": Overshoot easing. "spring": Spring-like easing.

EffectColorSpace module-attribute

EffectColorSpace: TypeAlias = Literal['rgb', 'hsl', 'hsv']

Color interpolation space for color-driven effects.

Values

"rgb": Interpolate in RGB space. "hsl": Interpolate in HSL space. "hsv": Interpolate in HSV space.

EffectCellFilter module-attribute

EffectCellFilter: TypeAlias = Literal[
    "all",
    "text",
    "non_empty",
    "background",
    "background_only",
]

Terminal cells selected by an effect.

Values

"all": Every cell in the target field area. "text": Cells containing text-like characters. "non_empty": Cells whose symbol is not a space. "background": Cells carrying a non-reset background color. "background_only": Blank cells carrying a non-reset background; styled text cells are excluded.

KnownEffectKind module-attribute

KnownEffectKind: TypeAlias = Literal[
    "fade",
    "fade_from",
    "fade_to",
    "fade_from_both",
    "dissolve",
    "coalesce",
    "sweep_in",
    "sweep_out",
    "slide_in",
    "slide_out",
    "paint",
    "paint_fg",
    "paint_bg",
    "sleep",
    "sequence",
    "parallel",
    "repeat",
    "delay",
]

Built-in effect kinds that can be composed through Effect or a controller's play_effect.

Values

"fade": Fade foreground color to a target. "fade_from": Fade foreground color from a source. "fade_to": Fade foreground and background to targets. "fade_from_both": Fade foreground and background from sources. "dissolve": Random pixel dissolve transition. "coalesce": Typewriter-style cell assembly. "sweep_in": Directional sweep revealing content. "sweep_out": Directional sweep hiding content. "slide_in": Directional slide revealing content. "slide_out": Directional slide hiding content. "paint": Paint foreground and background to targets. "paint_fg": Paint foreground to a target color. "paint_bg": Paint background to a target color. "sleep": No-op delay for sequencing. "sequence": Run child effects one after another. "parallel": Run child effects simultaneously. "repeat": Repeat a child effect. "delay": Delay before starting a child effect.

AbstractEffect dataclass

AbstractEffect(
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: ABC

Abstract base for user-composed visual effects.

Subclasses describe effect intent with xnano types and literals. A controller lowers them to whatever native effect representation it understands. Terminal and web surfaces both lower these descriptions through the runtime.

Attributes:

Examples:

effect = FadeEffect(color="violet", duration_ms=250)
self.grid_effect(effect, fields=["content"])

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

FadeEffect dataclass

FadeEffect(
    color: ColorLike = "white",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Fade foreground color to a target color.

Attributes:

color class-attribute instance-attribute

color: ColorLike = 'white'

Target foreground color.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

FadeFromEffect dataclass

FadeFromEffect(
    color: ColorLike = "white",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Fade foreground color from a source color.

Attributes:

color class-attribute instance-attribute

color: ColorLike = 'white'

Source foreground color.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

FadeToEffect dataclass

FadeToEffect(
    color: ColorLike = "white",
    background: ColorLike = "black",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Fade foreground and background to target colors.

Attributes:

color class-attribute instance-attribute

color: ColorLike = 'white'

Target foreground color.

background class-attribute instance-attribute

background: ColorLike = 'black'

Target background color.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

FadeFromBothEffect dataclass

FadeFromBothEffect(
    color: ColorLike = "white",
    background: ColorLike = "black",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Fade foreground and background from source colors.

Attributes:

color class-attribute instance-attribute

color: ColorLike = 'white'

Source foreground color.

background class-attribute instance-attribute

background: ColorLike = 'black'

Source background color.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

DissolveEffect dataclass

DissolveEffect(
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Random pixel dissolve transition.

Attributes:

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

CoalesceEffect dataclass

CoalesceEffect(
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Typewriter-style cell assembly.

Attributes:

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

DirectionalEffect dataclass

DirectionalEffect(
    direction: EffectMotion = "left_to_right",
    gradient_length: int = 14,
    randomness: int = 2,
    color: ColorLike = "white",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Shared parameters for slide and sweep effects.

Attributes:

direction class-attribute instance-attribute

direction: EffectMotion = 'left_to_right'

Direction the effect travels across the target area.

gradient_length class-attribute instance-attribute

gradient_length: int = 14

Length of the motion gradient in cells.

randomness class-attribute instance-attribute

randomness: int = 2

Randomness applied along the gradient.

color class-attribute instance-attribute

color: ColorLike = 'white'

Accent color used by the motion gradient.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

SweepInEffect dataclass

SweepInEffect(
    direction: EffectMotion = "left_to_right",
    gradient_length: int = 14,
    randomness: int = 2,
    color: ColorLike = "white",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: DirectionalEffect

Directional sweep revealing content.

Attributes:

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

direction class-attribute instance-attribute

direction: EffectMotion = 'left_to_right'

Direction the effect travels across the target area.

gradient_length class-attribute instance-attribute

gradient_length: int = 14

Length of the motion gradient in cells.

randomness class-attribute instance-attribute

randomness: int = 2

Randomness applied along the gradient.

color class-attribute instance-attribute

color: ColorLike = 'white'

Accent color used by the motion gradient.

SweepOutEffect dataclass

SweepOutEffect(
    direction: EffectMotion = "left_to_right",
    gradient_length: int = 14,
    randomness: int = 2,
    color: ColorLike = "white",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: DirectionalEffect

Directional sweep hiding content.

Attributes:

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

direction class-attribute instance-attribute

direction: EffectMotion = 'left_to_right'

Direction the effect travels across the target area.

gradient_length class-attribute instance-attribute

gradient_length: int = 14

Length of the motion gradient in cells.

randomness class-attribute instance-attribute

randomness: int = 2

Randomness applied along the gradient.

color class-attribute instance-attribute

color: ColorLike = 'white'

Accent color used by the motion gradient.

SlideInEffect dataclass

SlideInEffect(
    direction: EffectMotion = "left_to_right",
    gradient_length: int = 14,
    randomness: int = 2,
    color: ColorLike = "white",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: DirectionalEffect

Directional slide revealing content.

Attributes:

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

direction class-attribute instance-attribute

direction: EffectMotion = 'left_to_right'

Direction the effect travels across the target area.

gradient_length class-attribute instance-attribute

gradient_length: int = 14

Length of the motion gradient in cells.

randomness class-attribute instance-attribute

randomness: int = 2

Randomness applied along the gradient.

color class-attribute instance-attribute

color: ColorLike = 'white'

Accent color used by the motion gradient.

SlideOutEffect dataclass

SlideOutEffect(
    direction: EffectMotion = "left_to_right",
    gradient_length: int = 14,
    randomness: int = 2,
    color: ColorLike = "white",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: DirectionalEffect

Directional slide hiding content.

Attributes:

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

direction class-attribute instance-attribute

direction: EffectMotion = 'left_to_right'

Direction the effect travels across the target area.

gradient_length class-attribute instance-attribute

gradient_length: int = 14

Length of the motion gradient in cells.

randomness class-attribute instance-attribute

randomness: int = 2

Randomness applied along the gradient.

color class-attribute instance-attribute

color: ColorLike = 'white'

Accent color used by the motion gradient.

PaintEffect dataclass

PaintEffect(
    color: ColorLike = "white",
    background: ColorLike = "black",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Paint foreground and background to target colors.

Attributes:

color class-attribute instance-attribute

color: ColorLike = 'white'

Target foreground color.

background class-attribute instance-attribute

background: ColorLike = 'black'

Target background color.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

PaintForegroundEffect dataclass

PaintForegroundEffect(
    color: ColorLike = "white",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Paint foreground to a target color.

Attributes:

color class-attribute instance-attribute

color: ColorLike = 'white'

Target foreground color.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

PaintBackgroundEffect dataclass

PaintBackgroundEffect(
    background: ColorLike = "black",
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Paint background to a target color.

Attributes:

background class-attribute instance-attribute

background: ColorLike = 'black'

Target background color.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

SleepEffect dataclass

SleepEffect(
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

No-op delay used when composing effect sequences.

Attributes:

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

SequenceEffect dataclass

SequenceEffect(
    effects: tuple[AbstractEffect, ...] = (),
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Run child effects one after another.

Attributes:

effects class-attribute instance-attribute

effects: tuple[AbstractEffect, ...] = ()

Child effects to run in order.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

ParallelEffect dataclass

ParallelEffect(
    effects: tuple[AbstractEffect, ...] = (),
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Run child effects simultaneously.

Attributes:

effects class-attribute instance-attribute

effects: tuple[AbstractEffect, ...] = ()

Child effects to run in parallel.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

RepeatEffect dataclass

RepeatEffect(
    child: AbstractEffect | None = None,
    times: int | None = None,
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Repeat a child effect.

Attributes:

child class-attribute instance-attribute

child: AbstractEffect | None = None

Effect to repeat.

times class-attribute instance-attribute

times: int | None = None

Number of times to repeat the child effect.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

DelayEffect dataclass

DelayEffect(
    child: AbstractEffect | None = None,
    *,
    duration_ms: int = 300,
    interpolation: EffectInterpolation | None = None,
    cell_filter: EffectCellFilter | None = None,
    key: str | None = None
)

Bases: AbstractEffect

Delay before starting a child effect.

Attributes:

child class-attribute instance-attribute

child: AbstractEffect | None = None

Effect to start after the delay.

duration_ms class-attribute instance-attribute

duration_ms: int = dataclasses.field(
    default=300, kw_only=True
)

Duration of the effect in milliseconds.

interpolation class-attribute instance-attribute

interpolation: EffectInterpolation | None = (
    dataclasses.field(default=None, kw_only=True)
)

Optional interpolation curve for the effect.

cell_filter class-attribute instance-attribute

cell_filter: EffectCellFilter | None = dataclasses.field(
    default=None, kw_only=True
)

Optional terminal-cell selection applied by the controller.

key class-attribute instance-attribute

key: str | None = dataclasses.field(
    default=None, kw_only=True
)

Optional identity for this effect instance.

Used by a controller to derive a stable, de-duplicating id per target field (e.g. f"{key}:{field_name}") so replaying the same effect kind on the same field replaces the running instance instead of stacking a new one. Left unset, the controller falls back to the field name alone.

EffectHandle dataclass

EffectHandle(
    keys: tuple[str, ...] = (),
    runtime: Any = None,
    effect: "AbstractEffect | None" = None,
    fields: tuple[str, ...] = (),
    loop_in_context: bool = False,
)

A running effect, per target field.

Truthy when at least one target field had a rendered area, so if self.grid_effect(...) keeps working. Also a context manager: the effect is cancelled on exit, which is how an effect is scoped to a block rather than to a duration.

Example
with self.grid_effect("pulse", fields=["body"]):
    do_slow_work()

Methods:

  • cancel

    Stop the effect on every target field. Idempotent.

Attributes:

  • keys (tuple[str, ...]) –

    Session keys this handle cancels, one per target field.

  • runtime (Any) –

    Runtime that registered the effect.

  • effect ('AbstractEffect | None') –

    Resolved effect, replayed on __enter__ when looping.

  • fields (tuple[str, ...]) –

    Target field names, for replay.

  • loop_in_context (bool) –

    Whether entering a with block should loop the effect.

  • active (bool) –

    Whether the effect is still animating.

keys class-attribute instance-attribute

keys: tuple[str, ...] = ()

Session keys this handle cancels, one per target field.

runtime class-attribute instance-attribute

runtime: Any = None

Runtime that registered the effect.

effect class-attribute instance-attribute

effect: 'AbstractEffect | None' = None

Resolved effect, replayed on __enter__ when looping.

fields class-attribute instance-attribute

fields: tuple[str, ...] = ()

Target field names, for replay.

loop_in_context class-attribute instance-attribute

loop_in_context: bool = False

Whether entering a with block should loop the effect.

active property

active: bool

Whether the effect is still animating.

False once cancelled. Otherwise reflects the session's own animation state, which is shared across effects — see Runtime.is_animating.

cancel

cancel() -> None

Stop the effect on every target field. Idempotent.

Source code in xnano/effects.py
def cancel(self) -> None:
    """Stop the effect on every target field. Idempotent."""
    if self._cancelled or self.runtime is None:
        return
    for key in self.keys:
        self.runtime.cancel_effect(key)
    self._cancelled = True

resolve_effect

resolve_effect(
    effect: AbstractEffect | 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,
    key: str | None = None
) -> AbstractEffect

Resolve an effect description into an AbstractEffect.

Parameters:

  • effect (AbstractEffect | KnownEffectKind) –

    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.

  • key (str | None, default: None ) –

    Identity used by a controller to de-duplicate this effect per target field. Ignored when effect is already an AbstractEffect instance — set key on the instance itself in that case.

Returns:

Source code in xnano/effects.py
def resolve_effect(
    effect: AbstractEffect | 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,
    key: str | None = None,
) -> AbstractEffect:
    """Resolve an effect description into an ``AbstractEffect``.

    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.
        key: Identity used by a controller to de-duplicate this effect
            per target field. Ignored when ``effect`` is already an
            ``AbstractEffect`` instance — set ``key`` on the instance
            itself in that case.

    Returns:
        A resolved ``AbstractEffect`` instance.
    """
    if isinstance(effect, AbstractEffect):
        return effect
    return _build_effect_from_kind(
        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,
        key=key,
    )

Effect

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,
    key: str | None = None
) -> AbstractEffect
Effect(
    effect: 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,
    key: str | None = None
) -> AbstractEffect
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,
    key: str | None = None
) -> AbstractEffect

Create a user-facing effect description.

Parameters:

  • effect (KnownEffectKind | AbstractEffect) –

    A known effect kind or an existing effect instance.

  • 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.

  • key (str | None, default: None ) –

    Identity used by a controller to de-duplicate this effect per target field, e.g. distinguishing two independently triggered "fade" effects on the same grid.

Returns:

Source code in xnano/effects.py
def 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,
    key: str | None = None,
) -> AbstractEffect:
    """Create a user-facing effect description.

    Args:
        effect: A known effect kind or an existing effect instance.
        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.
        key: Identity used by a controller to de-duplicate this effect
            per target field, e.g. distinguishing two independently
            triggered ``"fade"`` effects on the same grid.

    Returns:
        A resolved ``AbstractEffect`` instance.
    """
    return resolve_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,
        key=key,
    )