Skip to content

xnano.fields

xnano.fields

xnano.fields


Declare renderable layout slots and non-rendered state on a BaseGrid. Each field can also control sizing, style, focus, scrolling, and movement.

Classes:

  • GridFieldInfo

    Descriptor class for layout, frame and additional rendering metadata for

  • FieldState

    Per-instance live state for one field on an AbstractInterface.

Functions:

  • Field

    Create a new grid field info instance.

Attributes:

ClassNameLike module-attribute

ClassNameLike: TypeAlias = Union[
    "TailwindClass",
    str,
    "list[TailwindClass | str]",
    "tuple[TailwindClass | str, ...]",
]

Tailwind classes as a single class, a space-separated string, or a list of class tokens. See xnano.tailwind.TailwindClass for the full supported vocabulary; unknown tokens are carried verbatim to the web backend and ignored by the terminal.

GridFieldInfo dataclass

GridFieldInfo(
    *,
    default: Any = UNSET,
    strict: bool = False,
    default_factory: Callable[[], Any] | None = None,
    state: bool | None = None,
    init: bool = True,
    visible: bool | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    foreground: ColorLike | None = None,
    background: ColorLike | None = None,
    fill: bool | None = None,
    width: "Sizing | None" = None,
    height: "Sizing | None" = None,
    gap: int | None = None,
    direction: Direction | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    border: Border | None = None,
    border_sides: Sequence[Side] | None = None,
    border_color: ColorLike | None = None,
    title: str | None = None,
    title_position: FrameTitlePosition | None = None,
    padding: PaddingLike | None = None,
    slide: list[str] | None = None,
    group: str | None = None,
    autofocus: bool | None = None,
    scroll: "types.ScrollLike | None" = None,
    wireframe: bool | None = None,
    class_name: tuple[str, ...] | None = None,
    margin: PaddingLike | None = None,
    z: int | None = None,
    overlay: bool = False
)

Descriptor class for layout, frame and additional rendering metadata for a field within a grid.

Examples:

from xnano import BaseGrid, Field

class MyGrid(BaseGrid):
    title: str = Field(default="My BaseGrid")
    data: int = Field(default=0, state=True)

Attributes:

  • default (Any) –

    Static default value for this field.

  • default_factory (Callable[[], Any] | None) –

    Callable that produces the default value each time an instance is created.

  • state (bool | None) –

    Whether this field is a stateful field (does not ever represent renderable content).

  • strict (bool) –

    When True and this field is a state field, assignments are validated against the field's type annotation using pydantic_core.

  • init (bool) –

    Whether this field should be included within the constructor of it's parent grid class.

  • visible (bool | None) –

    Whether this field is visible on the live terminal display.

  • modifiers (Sequence[CharacterModifier] | None) –

    Modifiers to apply to all characters within this field. This can be a list including "bold", "dim", "italic", "underline", "slow_blink", "rapid_blink", "reversed".

  • foreground (ColorLike | None) –

    The foreground color of content within this field.

  • color (ColorLike | None) –

    Deprecated alias for foreground; passing it emits a DeprecationWarning and sets the foreground.

  • background (ColorLike | None) –

    The background color of this field. Fills the whole slot by default when set (see fill); also fills the framed content area when the field defines border/title/padding chrome.

  • fill (bool | None) –

    Whether background fills the whole slot. None fills when a background is set; True forces a full-slot fill; False paints the color only behind text glyphs.

  • width ('Sizing | None') –

    Horizontal extent sizing (10, "50%", "1fr", "fit", or a Sizing). Drives the split constraint in horizontal layouts; shrinks the slot along the cross axis otherwise.

  • height ('Sizing | None') –

    Vertical extent sizing (3, "50%", "1fr", "fit", or a Sizing). Drives the split constraint in vertical layouts; shrinks the slot along the cross axis otherwise.

  • gap (int | None) –

    The gap between fields in this field or area.

  • direction (Direction | None) –

    The direction in which content within this field or area should be laid out.

  • horizontal_align (Alignment | None) –

    The horizontal alignment of content within this field's area.

  • vertical_align (VerticalAlignment | None) –

    The vertical alignment of content within this field's area.

  • border (Border | None) –

    A border style to be applied onto the outer frame of the rectangular area this field occupies.

  • border_sides (Sequence[Side] | None) –

    The sides of the border to be applied onto the outer frame of the area this field occupies.

  • border_color (ColorLike | None) –

    The color of this field's border, if one is set.

  • title (str | None) –

    A title to be displayed around the outer frame of this field's area.

  • title_position (FrameTitlePosition | None) –

    The alignment of the title within the outer frame of this field's area.

  • padding (PaddingLike | None) –

    The padding to be applied around the content area of this field.

  • slide (list[str] | None) –

    The axes along which this field may slide within its parent grid.

  • group (str | None) –

    Terminal-wide focus and event group.

  • autofocus (bool | None) –

    Whether the field receives focus by default.

  • scroll ('types.ScrollLike | None') –

    Whether container content scrolls when it exceeds its area.

  • wireframe (bool | None) –

    Whether to draw the field's debug cell grid.

  • class_name (tuple[str, ...] | None) –

    Tailwind utility classes applied to the field.

  • margin (PaddingLike | None) –

    Space outside the field's allocated area.

Methods:

  • get_style

    Return the unified Style for this field's chrome and text.

default class-attribute instance-attribute

default: Any = UNSET

Static default value for this field.

strict class-attribute instance-attribute

strict: bool = False

When True and this field is a state field, assignments are validated against the field's type annotation using pydantic_core.

default_factory class-attribute instance-attribute

default_factory: Callable[[], Any] | None = None

Callable that produces the default value each time an instance is created.

state class-attribute instance-attribute

state: bool | None = None

Whether this field is a stateful field (does not ever represent renderable content).

init class-attribute instance-attribute

init: bool = True

Whether this field should be included within the constructor of it's parent grid class.

visible class-attribute instance-attribute

visible: bool | None = None

Whether this field is visible on the live terminal display.

modifiers class-attribute instance-attribute

modifiers: Sequence[CharacterModifier] | None = None

Modifiers to apply to all characters within this field.

This can be a list of any of the following modifiers
  • "bold": Renders the content in bold.
  • "dim": The content is rendered with reduced intensity.
  • "italic": Renders the content in italics.
  • "underline": Adds an underline beneath the content.
  • "slow_blink": Causes the content to blink slowly.
  • "rapid_blink": Causes the content to blink rapidly.
  • "reversed": Swaps foreground and background colors.

foreground class-attribute instance-attribute

foreground: ColorLike | None = None

The foreground color of content within this field.

background class-attribute instance-attribute

background: ColorLike | None = None

The background color of content within this field.

By default a background fills the field's whole slot (fill is treated as True when a background is set). Pass fill=False to revert to the accent-behind-glyphs behavior, where the color paints only behind text cells. When the field also defines border, title, or padding chrome, the color fills the framed content area regardless of fill.

fill class-attribute instance-attribute

fill: bool | None = None

Whether background fills the whole slot.

None (the default) fills when a background is set; True forces a full-slot fill; False paints the color only behind text glyphs.

width class-attribute instance-attribute

width: 'Sizing | None' = None

Sizing intent for the field's horizontal extent.

Accepts any Sizing or shorthand (10 cells, "50%", "1fr", "fit"). When the grid lays out horizontally this drives the split constraint; otherwise it shrinks the slot to this width.

height class-attribute instance-attribute

height: 'Sizing | None' = None

Sizing intent for the field's vertical extent.

Accepts any Sizing or shorthand (3 cells, "50%", "1fr", "fit"). When the grid lays out vertically this drives the split constraint; otherwise it shrinks the slot to this height.

gap class-attribute instance-attribute

gap: int | None = None

The gap between fields in this field or area.

direction class-attribute instance-attribute

direction: Direction | None = None

The direction in which content within this field or area should be laid out.

horizontal_align class-attribute instance-attribute

horizontal_align: Alignment | None = None

The horizontal alignment of content within this field's area.

vertical_align class-attribute instance-attribute

vertical_align: VerticalAlignment | None = None

The vertical alignment of content within this field's area.

border class-attribute instance-attribute

border: Border | None = None

A border style to be applied onto the outer frame of the rectangular area this field occupies.

border_sides class-attribute instance-attribute

border_sides: Sequence[Side] | None = None

The sides of the border to be applied onto the outer frame of the area this field occupies.

border_color class-attribute instance-attribute

border_color: ColorLike | None = None

The color of this field's border, if one is set.

title class-attribute instance-attribute

title: str | None = None

A title to be displayed around the outer frame of this field's area.

title_position class-attribute instance-attribute

title_position: FrameTitlePosition | None = None

The alignment of the title within the outer frame of this field's area.

padding class-attribute instance-attribute

padding: PaddingLike | None = None

The padding to be applied around the content area of this field.

slide class-attribute instance-attribute

slide: list[str] | None = None

The axes along which this field may slide within its parent grid.

group class-attribute instance-attribute

group: str | None = None

Terminal-global focus/event identifier. Fields on different grids that share a group are addressed together by ctx.focus(group), @on_focus(group=...), and @on_click(group=...) — no grid reference or nesting knowledge required.

autofocus class-attribute instance-attribute

autofocus: bool | None = None

Whether this field receives focus by default when nothing else is focused yet (preferred over declaration-order default selection).

scroll class-attribute instance-attribute

scroll: 'types.ScrollLike | None' = None

Enable windowed scrolling for a field whose content overflows its slot.

True/"vertical" scrolls rows; "horizontal" scrolls columns. A scroll field reserves its full slot height (short content leaves blank rows) and the mouse wheel moves it automatically. Drive it programmatically through ctx.scroll(group).scroll(delta), .scroll_to(offset), .scroll_to_end() (tail-follow). Offset 0 shows the top; increasing the offset reveals later content.

wireframe class-attribute instance-attribute

wireframe: bool | None = None

Live-toggle a debug overlay showing the cell grid this field occupies. Content renders normally underneath; this only adds a thin per-cell lattice on top. Toggle live via grid_set_field/ grid_update_field.

class_name class-attribute instance-attribute

class_name: tuple[str, ...] | None = None

Tailwind CSS class tokens attached to this field.

Normalized from the class_name argument to Field. The web backend emits these classes verbatim; the terminal backend renders through the lowered attributes instead.

margin class-attribute instance-attribute

margin: PaddingLike | None = None

The margin to be applied around the outer area of this field.

Also populated by Tailwind m*-{n} classes through class_name; the terminal insets the field's slot by this amount before painting.

z class-attribute instance-attribute

z: int | None = None

Layering order for this field's slot, relative to its grid.

None inherits the grid's own z; an explicit value stacks the field's whole subtree — plain text, a component, or a nested grid — above (or below) its siblings. It is additive with the grid's z and any nested field z, so an overlay field lifts everything it contains together. Live-toggle via grid_set_field/grid_update_field.

overlay class-attribute instance-attribute

overlay: bool = False

Float this field over the grid instead of giving it a layout slot.

A normal field claims a share of the layout; an overlay field is taken out of the flow and painted on top of the grid's content area, sized by its width/height (percent, cells, or ratio; unset fills the area) and centered. Pair it with a higher z for a popup or modal that covers the panels behind it rather than pushing them aside. Hidden overlays (visible=False) cost nothing until shown.

style property

style: Style

Unified styling for this field (see get_style).

get_style

get_style() -> Style

Return the unified Style for this field's chrome and text.

Flat style attributes on FieldInfo remain the storage for one release; this method is the single composition point consumers should prefer going forward.

Returns:

  • Style

    A Style assembled from this field's style attributes.

Source code in xnano/fields.py
def get_style(self) -> Style:
    """Return the unified ``Style`` for this field's chrome and text.

    Flat style attributes on ``FieldInfo`` remain the storage for one
    release; this method is the single composition point consumers
    should prefer going forward.

    Returns:
        A ``Style`` assembled from this field's style attributes.
    """
    modifiers = tuple(self.modifiers) if self.modifiers else ()
    border_sides = (
        tuple(self.border_sides) if self.border_sides is not None else None
    )
    classes = self.class_name if self.class_name is not None else ()
    return Style(
        foreground=self.foreground,
        background=self.background,
        border=self.border,
        border_color=self.border_color,
        border_sides=border_sides,
        padding=(
            area.Padding.parse(self.padding)
            if self.padding is not None
            and not isinstance(self.padding, area.Padding)
            else self.padding  # type: ignore[arg-type]
        ),
        margin=(
            area.Padding.parse(self.margin)
            if self.margin is not None
            and not isinstance(self.margin, area.Padding)
            else self.margin  # type: ignore[arg-type]
        ),
        gap=self.gap,
        width=self.width,
        height=self.height,
        modifiers=modifiers,
        horizontal_align=self.horizontal_align,
        direction=self.direction,
        title=self.title,
        title_position=self.title_position,
        visible=self.visible,
        classes=classes,
        passthrough_classes=(),
    )

FieldState dataclass

FieldState(
    name: str,
    value: Any = None,
    focused: bool = False,
    hovered: bool = False,
    dirty: bool = False,
    slide_position: Coordinate | None = None,
    overrides: dict[str, Any] = dict(),
)

Per-instance live state for one field on an AbstractInterface.

Attributes:

  • name (str) –

    Field name on the owning interface.

  • value (Any) –

    Current value (mirrors the instance attribute).

  • focused (bool) –

    Whether this field holds application focus.

  • hovered (bool) –

    Whether a pointer is over this field's slot.

  • dirty (bool) –

    Whether the value or overrides changed since last paint.

  • slide_position (Coordinate | None) –

    Optional drag offset for slidable fields.

  • overrides (dict[str, Any]) –

    Per-instance style/layout overrides.

Examples:

Inspect live state without changing the field descriptor:

state = grid.grid_get_field_state("search")
if state.focused:
    ...

Methods:

  • mark_dirty

    Mark this field as needing a repaint / patch.

  • clear_dirty

    Clear the dirty bit after a successful paint / patch.

name instance-attribute

name: str

Field name on the owning interface.

value class-attribute instance-attribute

value: Any = None

Current value (mirrors the instance attribute).

focused class-attribute instance-attribute

focused: bool = False

Whether this field holds application focus.

hovered class-attribute instance-attribute

hovered: bool = False

Whether a pointer is over this field's slot.

dirty class-attribute instance-attribute

dirty: bool = False

Whether the value or overrides changed since last paint.

slide_position class-attribute instance-attribute

slide_position: Coordinate | None = None

Optional drag offset for slidable fields.

overrides class-attribute instance-attribute

overrides: dict[str, Any] = dataclasses.field(
    default_factory=dict
)

Per-instance style/layout overrides.

mark_dirty

mark_dirty() -> None

Mark this field as needing a repaint / patch.

Source code in xnano/fields.py
def mark_dirty(self) -> None:
    """Mark this field as needing a repaint / patch."""
    self.dirty = True

clear_dirty

clear_dirty() -> None

Clear the dirty bit after a successful paint / patch.

Source code in xnano/fields.py
def clear_dirty(self) -> None:
    """Clear the dirty bit after a successful paint / patch."""
    self.dirty = False

Field

Field(
    default: None,
    *,
    default_factory: None = None,
    state: bool = False,
    strict: bool = False,
    init: bool = True,
    visible: bool | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    foreground: ColorLike | None = None,
    color: ColorLike | None = _COLOR_UNSET,
    background: ColorLike | None = None,
    fill: bool | None = None,
    width: SizingLike | None = None,
    height: SizingLike | None = None,
    gap: int | None = None,
    direction: Direction | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    border: Border | None = None,
    border_sides: Sequence[Side] | None = None,
    border_color: ColorLike | None = None,
    title: str | None = None,
    title_position: FrameTitlePosition | None = None,
    padding: PaddingLike | None = None,
    margin: PaddingLike | None = None,
    z: int | None = None,
    overlay: bool = False,
    slide: Sequence[Axis] | None = None,
    group: str | None = None,
    autofocus: bool | None = None,
    scroll: ScrollLike | None = None,
    wireframe: bool | None = None,
    class_name: ClassNameLike | None = None,
    align: Alignment | None = None
) -> Any
Field(
    default: _T,
    *,
    default_factory: None = None,
    state: bool = False,
    strict: bool = False,
    init: bool = True,
    visible: bool | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    foreground: ColorLike | None = None,
    color: ColorLike | None = _COLOR_UNSET,
    background: ColorLike | None = None,
    fill: bool | None = None,
    width: SizingLike | None = None,
    height: SizingLike | None = None,
    gap: int | None = None,
    direction: Direction | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    border: Border | None = None,
    border_sides: Sequence[Side] | None = None,
    border_color: ColorLike | None = None,
    title: str | None = None,
    title_position: FrameTitlePosition | None = None,
    padding: PaddingLike | None = None,
    margin: PaddingLike | None = None,
    z: int | None = None,
    overlay: bool = False,
    slide: Sequence[Axis] | None = None,
    group: str | None = None,
    autofocus: bool | None = None,
    scroll: ScrollLike | None = None,
    wireframe: bool | None = None,
    class_name: ClassNameLike | None = None,
    align: Alignment | None = None
) -> _T
Field(
    *,
    default_factory: Callable[[], _T],
    state: bool = False,
    strict: bool = False,
    init: bool = True,
    visible: bool | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    foreground: ColorLike | None = None,
    color: ColorLike | None = _COLOR_UNSET,
    background: ColorLike | None = None,
    fill: bool | None = None,
    width: SizingLike | None = None,
    height: SizingLike | None = None,
    gap: int | None = None,
    direction: Direction | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    border: Border | None = None,
    border_sides: Sequence[Side] | None = None,
    border_color: ColorLike | None = None,
    title: str | None = None,
    title_position: FrameTitlePosition | None = None,
    padding: PaddingLike | None = None,
    margin: PaddingLike | None = None,
    z: int | None = None,
    overlay: bool = False,
    slide: Sequence[Axis] | None = None,
    group: str | None = None,
    autofocus: bool | None = None,
    scroll: ScrollLike | None = None,
    wireframe: bool | None = None,
    class_name: ClassNameLike | None = None,
    align: Alignment | None = None
) -> _T
Field(
    *,
    default: Any = UNSET,
    default_factory: None = None,
    state: bool = False,
    strict: bool = False,
    init: bool = True,
    visible: bool | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    foreground: ColorLike | None = None,
    color: ColorLike | None = _COLOR_UNSET,
    background: ColorLike | None = None,
    fill: bool | None = None,
    width: SizingLike | None = None,
    height: SizingLike | None = None,
    gap: int | None = None,
    direction: Direction | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    border: Border | None = None,
    border_sides: Sequence[Side] | None = None,
    border_color: ColorLike | None = None,
    title: str | None = None,
    title_position: FrameTitlePosition | None = None,
    padding: PaddingLike | None = None,
    margin: PaddingLike | None = None,
    z: int | None = None,
    overlay: bool = False,
    slide: Sequence[Axis] | None = None,
    group: str | None = None,
    autofocus: bool | None = None,
    scroll: ScrollLike | None = None,
    wireframe: bool | None = None,
    class_name: ClassNameLike | None = None,
    align: Alignment | None = None
) -> Any
Field(
    default: Any = UNSET,
    *,
    default_factory: Callable[[], Any] | None = None,
    state: bool = False,
    strict: bool = False,
    init: bool = True,
    visible: bool | None = None,
    modifiers: Sequence[CharacterModifier] | None = None,
    foreground: ColorLike | None = None,
    color: ColorLike | None = _COLOR_UNSET,
    background: ColorLike | None = None,
    fill: bool | None = None,
    width: SizingLike | None = None,
    height: SizingLike | None = None,
    gap: int | None = None,
    direction: Direction | None = None,
    horizontal_align: Alignment | None = None,
    vertical_align: VerticalAlignment | None = None,
    border: Border | None = None,
    border_sides: Sequence[Side] | None = None,
    border_color: ColorLike | None = None,
    title: str | None = None,
    title_position: FrameTitlePosition | None = None,
    padding: PaddingLike | None = None,
    margin: PaddingLike | None = None,
    z: int | None = None,
    overlay: bool = False,
    slide: Sequence[Axis] | None = None,
    group: str | None = None,
    autofocus: bool | None = None,
    scroll: ScrollLike | None = None,
    wireframe: bool | None = None,
    class_name: ClassNameLike | None = None,
    align: Alignment | None = None
) -> GridFieldInfo

Create a new grid field info instance.

Parameters:

  • default (Any, default: UNSET ) –

    Static default value for this field.

  • default_factory (Callable[[], Any] | None, default: None ) –

    Callable that produces the default value each time an instance is created.

  • state (bool, default: False ) –

    Whether this field is a stateful field (does not ever represent renderable content).

  • strict (bool, default: False ) –

    When True and this field is a state field, assignments are validated against the field's type annotation using pydantic_core.

  • init (bool, default: True ) –

    Whether this field should be included within the constructor of it's parent grid class.

  • visible (bool | None, default: None ) –

    Whether this field is visible on the live terminal display.

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

    Modifiers to apply to all characters within this field. This can be a list including "bold", "dim", "italic", "underline", "slow_blink", "rapid_blink", "reversed".

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

    The foreground color of content within this field.

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

    Deprecated alias for foreground; passing it emits a DeprecationWarning and sets the foreground.

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

    The background color of this field. Fills the whole slot by default when set (see fill); also fills the framed content area when the field defines border/title/padding chrome.

  • fill (bool | None, default: None ) –

    Whether background fills the whole slot. None fills when a background is set; True forces a full-slot fill; False paints the color only behind text glyphs.

  • width (SizingLike | None, default: None ) –

    Horizontal extent sizing (10, "50%", "1fr", "fit", or a Sizing). Drives the split constraint in horizontal layouts; shrinks the slot along the cross axis otherwise.

  • height (SizingLike | None, default: None ) –

    Vertical extent sizing (3, "50%", "1fr", "fit", or a Sizing). Drives the split constraint in vertical layouts; shrinks the slot along the cross axis otherwise.

  • gap (int | None, default: None ) –

    The gap between fields in this field or area.

  • direction (Direction | None, default: None ) –

    The direction in which content within this field or area should be laid out.

  • horizontal_align (Alignment | None, default: None ) –

    The horizontal alignment of content within this field's area.

  • vertical_align (VerticalAlignment | None, default: None ) –

    The vertical alignment of content within this field's area.

  • border (Border | None, default: None ) –

    A border style to be applied onto the outer frame of the rectangular area this field occupies.

  • border_sides (Sequence[Side] | None, default: None ) –

    The sides of the border to be applied onto the outer frame of the area this field occupies.

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

    The color of this field's border, if one is set.

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

    A title to be displayed around the outer frame of this field's area.

  • title_position (FrameTitlePosition | None, default: None ) –

    The alignment of the title within the outer frame of this field's area.

  • padding (PaddingLike | None, default: None ) –

    The padding to be applied around the content area of this field.

  • margin (PaddingLike | None, default: None ) –

    The margin to be applied around the outer area of this field.

  • z (int | None, default: None ) –

    Layering order for this field's slot relative to its grid. None inherits the grid's own z; an explicit value stacks the field's whole subtree (text, component, or nested grid) above or below its siblings and is additive with the grid's z.

  • overlay (bool, default: False ) –

    Float this field over the grid's content area (centered, sized by width/height) instead of giving it a layout slot. Pair with a higher z for a popup or modal over the panels behind it.

  • slide (Sequence[Axis] | None, default: None ) –

    The axes along which this field may slide within its parent grid.

  • class_name (ClassNameLike | None, default: None ) –

    Tailwind CSS classes styling this field — a space-separated string or a sequence of class tokens. Classes are lowered into the standard field attributes (see xnano.tailwind); an explicit keyword argument always overrides a class-derived value. Classes with no terminal equivalent are ignored by the terminal backend and emitted verbatim by the web backend.

Returns:

  • GridFieldInfo

    A new GridFieldInfo instance with all display/layout metadata,

  • GridFieldInfo

    including the normalized class_name tokens.

Source code in xnano/fields.py
def Field(
    default: Any = UNSET,
    *,
    default_factory: Callable[[], Any] | None = None,
    state: bool = False,
    strict: bool = False,
    init: bool = True,
    visible: bool | None = None,
    modifiers: Sequence[types.CharacterModifier] | None = None,
    foreground: ColorLike | None = None,
    color: ColorLike | None = _COLOR_UNSET,
    background: ColorLike | None = None,
    fill: bool | None = None,
    width: SizingLike | None = None,
    height: SizingLike | None = None,
    gap: int | None = None,
    direction: types.Direction | None = None,
    horizontal_align: area.Alignment | None = None,
    vertical_align: area.VerticalAlignment | None = None,
    border: types.Border | None = None,
    border_sides: Sequence[types.Side] | None = None,
    border_color: ColorLike | None = None,
    title: str | None = None,
    title_position: FrameTitlePosition | None = None,
    padding: area.PaddingLike | None = None,
    margin: area.PaddingLike | None = None,
    z: int | None = None,
    overlay: bool = False,
    slide: Sequence[types.Axis] | None = None,
    group: str | None = None,
    autofocus: bool | None = None,
    scroll: types.ScrollLike | None = None,
    wireframe: bool | None = None,
    class_name: ClassNameLike | None = None,
    align: area.Alignment | None = None,
) -> GridFieldInfo:
    """Create a new grid field info instance.

    Args:
        default: Static default value for this field.
        default_factory: Callable that produces the default value each time an instance is created.
        state: Whether this field is a stateful field (does not ever represent renderable content).
        strict: When ``True`` and this field is a state field, assignments are validated
            against the field's type annotation using ``pydantic_core``.
        init: Whether this field should be included within the constructor of it's parent grid class.
        visible: Whether this field is visible on the live terminal display.
        modifiers: Modifiers to apply to all characters within this field. This can be a list
            including "bold", "dim", "italic", "underline", "slow_blink", "rapid_blink",
            "reversed".
        foreground: The foreground color of content within this field.
        color: Deprecated alias for ``foreground``; passing it emits a
            ``DeprecationWarning`` and sets the foreground.
        background: The background color of this field. Fills the whole slot by
            default when set (see ``fill``); also fills the framed content area
            when the field defines border/title/padding chrome.
        fill: Whether ``background`` fills the whole slot. ``None`` fills when a
            background is set; ``True`` forces a full-slot fill; ``False`` paints
            the color only behind text glyphs.
        width: Horizontal extent sizing (``10``, ``"50%"``, ``"1fr"``, ``"fit"``,
            or a ``Sizing``). Drives the split constraint in horizontal layouts;
            shrinks the slot along the cross axis otherwise.
        height: Vertical extent sizing (``3``, ``"50%"``, ``"1fr"``, ``"fit"``,
            or a ``Sizing``). Drives the split constraint in vertical layouts;
            shrinks the slot along the cross axis otherwise.
        gap: The gap between fields in this field or area.
        direction: The direction in which content within this field or area should be laid out.
        horizontal_align: The horizontal alignment of content within this
            field's area.
        vertical_align: The vertical alignment of content within this
            field's area.
        border: A border style to be applied onto the outer frame of the rectangular area this
            field occupies.
        border_sides: The sides of the border to be applied onto the outer frame of the area
            this field occupies.
        border_color: The color of this field's border, if one is set.
        title: A title to be displayed around the outer frame of this field's area.
        title_position: The alignment of the title within the outer frame of this
            field's area.
        padding: The padding to be applied around the content area of this field.
        margin: The margin to be applied around the outer area of this field.
        z: Layering order for this field's slot relative to its grid. ``None``
            inherits the grid's own ``z``; an explicit value stacks the field's
            whole subtree (text, component, or nested grid) above or below its
            siblings and is additive with the grid's ``z``.
        overlay: Float this field over the grid's content area (centered, sized
            by ``width``/``height``) instead of giving it a layout slot. Pair
            with a higher ``z`` for a popup or modal over the panels behind it.
        slide: The axes along which this field may slide within its parent grid.
        class_name: Tailwind CSS classes styling this field — a space-separated
            string or a sequence of class tokens. Classes are lowered into the
            standard field attributes (see ``xnano.tailwind``); an explicit
            keyword argument always overrides a class-derived value. Classes
            with no terminal equivalent are ignored by the terminal backend and
            emitted verbatim by the web backend.

    Returns:
        A new ``GridFieldInfo`` instance with all display/layout metadata,
        including the normalized ``class_name`` tokens.
    """
    if color is not _COLOR_UNSET:
        warn_color_alias(stacklevel=2)
        if foreground is None:
            foreground = color
    horizontal_align = resolve_renamed_alias(
        horizontal_align,
        align,
        old="align",
        new="horizontal_align",
        stacklevel=2,
    )
    tokens: tuple[str, ...] | None = None
    if class_name is not None:
        from xnano.tailwind import (
            normalize_tailwind_classes,
            resolve_tailwind_classes,
        )

        tokens = normalize_tailwind_classes(class_name)
        resolved = resolve_tailwind_classes(tokens)
        if foreground is None:
            foreground = resolved.foreground
        if background is None:
            background = resolved.background
        if border is None:
            border = resolved.border
        if border_color is None:
            border_color = resolved.border_color
        if border_sides is None:
            border_sides = resolved.border_sides
        if padding is None:
            padding = resolved.padding
        if margin is None:
            margin = resolved.margin
        if gap is None:
            gap = resolved.gap
        if width is None:
            width = resolved.width
        if height is None:
            height = resolved.height
        if modifiers is None and resolved.modifiers:
            modifiers = resolved.modifiers
        if horizontal_align is None:
            horizontal_align = resolved.horizontal_align
        if direction is None:
            direction = resolved.direction

    return GridFieldInfo(
        default=default,
        default_factory=default_factory,
        state=state,
        strict=strict,
        init=init,
        visible=visible,
        foreground=foreground,
        modifiers=modifiers,
        background=background,
        fill=fill,
        width=Sizing.parse(width),
        height=Sizing.parse(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,
        overlay=overlay,
        slide=_normalize_slide_axes(slide),
        group=group,
        autofocus=autofocus,
        scroll=scroll,
        wireframe=wireframe,
        class_name=tokens,
    )  # type: ignore[return-value]