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(TypeAlias) –Tailwind classes as a single class, a space-separated string, or a
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
Trueand this field is a state field, assignments are validated against the field's type annotation usingpydantic_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 aDeprecationWarningand 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
backgroundfills the whole slot.Nonefills when a background is set;Trueforces a full-slot fill;Falsepaints the color only behind text glyphs. -
width('Sizing | None') –Horizontal extent sizing (
10,"50%","1fr","fit", or aSizing). 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 aSizing). 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
Stylefor 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
¶
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
¶
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
¶
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
¶
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
¶
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
¶
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
¶
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.
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
Styleassembled from this field's style attributes.
Source code in xnano/fields.py
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:
Methods:
-
mark_dirty–Mark this field as needing a repaint / patch.
-
clear_dirty–Clear the dirty bit after a successful paint / patch.
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
¶
Per-instance style/layout overrides.
mark_dirty
¶
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
Trueand this field is a state field, assignments are validated against the field's type annotation usingpydantic_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 aDeprecationWarningand 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
backgroundfills the whole slot.Nonefills when a background is set;Trueforces a full-slot fill;Falsepaints the color only behind text glyphs. -
width(SizingLike | None, default:None) –Horizontal extent sizing (
10,"50%","1fr","fit", or aSizing). 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 aSizing). 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.
Noneinherits the grid's ownz; 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'sz. -
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 higherzfor 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
GridFieldInfoinstance with all display/layout metadata, -
GridFieldInfo–including the normalized
class_nametokens.
Source code in xnano/fields.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |