xnano.types
xnano.types
¶
xnano.types
Type aliases and values for layout, input, styling, charts, and components.
The geometry primitives (Area, Size, Padding, align_area,
and the alignment aliases) live in xnano.area. They are re-exported here,
deprecated, for the previous import path.
Classes:
-
Area–Rectangular region of a cell grid.
-
Padding–Padding around a rectangular area.
-
Size–Resolved width and height in cells.
-
Sizing–Single-axis layout size.
-
Frame–Border, title, background, and padding around content.
-
FieldFocus–Focused grid field.
-
ScrollHandle–Mutable scroll state for a field.
Functions:
-
align_area–Place a
widthxheightbox insideouteron both axes. -
resolve_flex_weight–Return the numeric layout weight represented by
flex. -
field_has_frame_chrome–Return whether a field defines structural frame styling.
-
field_fills_background–Return whether a field paints its background across the whole slot.
-
frame_from_field–Build frame styling from a field definition.
-
is_grid–Return whether a value is a grid instance.
-
is_component–Return whether a value follows the component contract.
-
uses_default_component_size–Return whether a component uses the default layout size.
-
is_focusable_component–Return whether a component accepts field focus.
Attributes:
-
Alignment(TypeAlias) –Horizontal (x-axis) alignment of a grid field or area.
-
Coordinate(TypeAlias) –A single
(x, y)cell coordinate within the terminal grid. -
PaddingLike(TypeAlias) –Padding around a rectangular area, in any accepted input form:
-
VerticalAlignment(TypeAlias) –Vertical (y-axis) alignment of a grid field or area.
-
ScrollLike(TypeAlias) –Field(scroll=...)value.Truescrolls along the field's -
Axis(TypeAlias) –The axis a grid field or area lays out along.
-
Border(TypeAlias) –Border style drawn around a rectangular area's outer edges.
-
Corner(TypeAlias) –A single corner of a rectangular grid area.
-
Direction(TypeAlias) –The direction content within a grid field or area lays out along.
-
CharacterModifier(TypeAlias) –A modifier applied to the content of a grid field or area.
-
ScrollbarOrientationLike(TypeAlias) –Placement of a scrollbar widget.
-
CanvasMarkerLike(TypeAlias) –Marker glyph set used when drawing on a Canvas widget.
-
GraphTypeLike(TypeAlias) –How a
Chartdataset is plotted. -
LegendPositionLike(TypeAlias) –Placement of a
Chart's legend within its area. -
Side(TypeAlias) –A single side of a rectangular grid area.
-
SizePercentage(TypeAlias) –Percentage of the parent area's width/height a field should occupy —
-
Flex(TypeAlias) –Relative fill weight for proportional layout, or a Tailwind flex
-
SizingKind(TypeAlias) –The kind of sizing intent expressed by a
Sizing. -
SizingKeyword(TypeAlias) –Named sizing keywords accepted by
Sizing.parse(plus the tailwind -
SizingPercentage(TypeAlias) –Whole-number percentage sizing strings
"0%"–"100%". Fractions and -
SizingLike(TypeAlias) –Any value accepted where a
Sizingis expected — seeSizing.parse -
FrameTitlePosition(TypeAlias) –The side of a frame to display its title on.
-
KnownKeyboardBinding(TypeAlias) –Commonly used keybindings accepted by
@on_keyboard. -
KeyboardModifier(TypeAlias) –A modifier key held alongside the primary action key.
-
KeyboardKey(TypeAlias) –Standard character/named keys accepted by
@on_keyboard. -
KeyboardBinding(TypeAlias) –A keyboard binding: a primary key optionally preceded by
+-joined -
MouseButton(TypeAlias) –The mouse button that triggered a mouse event.
Alignment
module-attribute
¶
Horizontal (x-axis) alignment of a grid field or area.
Values
"left": Aligned to the left.
"right": Aligned to the right.
"center": Centered.
Coordinate
module-attribute
¶
A single (x, y) cell coordinate within the terminal grid.
PaddingLike
module-attribute
¶
PaddingLike: TypeAlias = Union[
int,
tuple[int, int],
tuple[int | None, int | None, int | None, int | None],
"Padding",
]
Padding around a rectangular area, in any accepted input form:
- A single integer, applied to all four sides.
- A
(vertical, horizontal)tuple of two integers. - A
(top, right, bottom, left)tuple of four integers. - A
Paddinginstance.
VerticalAlignment
module-attribute
¶
Vertical (y-axis) alignment of a grid field or area.
Values
"top": Aligned to the top edge.
"middle": Centered vertically.
"bottom": Aligned to the bottom edge.
ScrollLike
module-attribute
¶
ScrollLike: TypeAlias = (
"bool | Literal['vertical', 'horizontal', 'auto']"
)
Field(scroll=...) value. True scrolls along the field's
direction; "vertical"/"horizontal" force an axis; "auto"
scrolls only when content overflows the slot.
Axis
module-attribute
¶
The axis a grid field or area lays out along.
Values
"x": Horizontal layout.
"y": Vertical layout.
Border
module-attribute
¶
Border: TypeAlias = Literal[
"plain",
"rounded",
"double",
"thick",
"quadrant_inside",
"quadrant_outside",
]
Border style drawn around a rectangular area's outer edges.
Values
"plain": A plain border. (---------)
"rounded": Rounded corners. (╭───────╮)
"double": Double lines. (╔═══════╗)
"thick": Thick/dark lines. (┏━━━━━━━┓)
"quadrant_inside": Quadrant-style inner division. (▛▀▀▀▀▀▜)
"quadrant_outside": Quadrant-style outer corners. (▗▄▄▄▄▄▖)
Corner
module-attribute
¶
A single corner of a rectangular grid area.
Values
"top-left", "top-right", "bottom-left", "bottom-right".
Direction
module-attribute
¶
The direction content within a grid field or area lays out along.
Values
"horizontal": Laid out horizontally.
"vertical": Laid out vertically.
CharacterModifier
module-attribute
¶
CharacterModifier: TypeAlias = Literal[
"bold",
"dim",
"italic",
"underline",
"slow_blink",
"rapid_blink",
"reversed",
]
A modifier applied to the content of a grid field or area.
Values
"bold": Bold text.
"dim": Reduced intensity.
"italic": Italic text.
"underline": Underlined text.
"slow_blink": Slow blink.
"rapid_blink": Rapid blink.
"reversed": Swapped foreground/background colors.
ScrollbarOrientationLike
module-attribute
¶
ScrollbarOrientationLike: TypeAlias = Literal[
"vertical_right",
"vertical_left",
"horizontal_bottom",
"horizontal_top",
]
Placement of a scrollbar widget.
Values
"vertical_right", "vertical_left": Vertical, right/left edge.
"horizontal_bottom", "horizontal_top": Horizontal, bottom/top
edge.
CanvasMarkerLike
module-attribute
¶
Marker glyph set used when drawing on a Canvas widget.
Values
"dot": Single-pixel dots.
"block": Full-block characters.
"bar": Horizontal bar characters.
"braille": Braille dot matrix (highest resolution).
"half_block": Half-block characters.
GraphTypeLike
module-attribute
¶
How a Chart dataset is plotted.
Values
"line": Connected line.
"scatter": Unconnected points.
"bar": Vertical bars.
LegendPositionLike
module-attribute
¶
LegendPositionLike: TypeAlias = Literal[
"top",
"top_right",
"top_left",
"left",
"right",
"bottom",
"bottom_right",
"bottom_left",
]
Placement of a Chart's legend within its area.
Side
module-attribute
¶
A single side of a rectangular grid area.
Values
"top", "bottom", "left", "right".
SizePercentage
module-attribute
¶
Percentage of the parent area's width/height a field should occupy —
a (width, height) tuple, or one float applied to both axes.
Flex
module-attribute
¶
Flex: TypeAlias = (
int
| Literal[
"flex-1",
"flex-auto",
"flex-initial",
"flex-none",
"grow",
"grow-0",
"shrink",
"shrink-0",
]
)
Relative fill weight for proportional layout, or a Tailwind flex
utility. Numeric values set the fill weight directly; Tailwind classes
map to proportional grow weights — see resolve_flex_weight.
SizingKind
module-attribute
¶
The kind of sizing intent expressed by a Sizing.
Values
"cells": A fixed cell count.
"percent": A percentage of the available axis length.
"ratio": A numerator / denominator fraction of the axis
length.
"fraction": A relative fill weight across leftover space.
"fit": The measured intrinsic size of the content.
SizingKeyword
module-attribute
¶
SizingKeyword: TypeAlias = Literal[
"fit",
"auto",
"content",
"fill",
"grow",
"grow-0",
"shrink",
"shrink-0",
"flex-1",
"flex-auto",
"flex-initial",
"flex-none",
"full",
]
Named sizing keywords accepted by Sizing.parse (plus the tailwind
full rewrite). Exposed as a Literal so editors autocomplete the common
string forms of width / height.
SizingPercentage
module-attribute
¶
SizingPercentage: TypeAlias = Literal[
"0%",
"1%",
"2%",
"3%",
"4%",
"5%",
"6%",
"7%",
"8%",
"9%",
"10%",
"11%",
"12%",
"13%",
"14%",
"15%",
"16%",
"17%",
"18%",
"19%",
"20%",
"21%",
"22%",
"23%",
"24%",
"25%",
"26%",
"27%",
"28%",
"29%",
"30%",
"31%",
"32%",
"33%",
"34%",
"35%",
"36%",
"37%",
"38%",
"39%",
"40%",
"41%",
"42%",
"43%",
"44%",
"45%",
"46%",
"47%",
"48%",
"49%",
"50%",
"51%",
"52%",
"53%",
"54%",
"55%",
"56%",
"57%",
"58%",
"59%",
"60%",
"61%",
"62%",
"63%",
"64%",
"65%",
"66%",
"67%",
"68%",
"69%",
"70%",
"71%",
"72%",
"73%",
"74%",
"75%",
"76%",
"77%",
"78%",
"79%",
"80%",
"81%",
"82%",
"83%",
"84%",
"85%",
"86%",
"87%",
"88%",
"89%",
"90%",
"91%",
"92%",
"93%",
"94%",
"95%",
"96%",
"97%",
"98%",
"99%",
"100%",
]
Whole-number percentage sizing strings "0%" – "100%". Fractions and
fr/ratio forms are deliberately left to the open str branch.
SizingLike
module-attribute
¶
SizingLike: TypeAlias = Union[
int, float, SizingKeyword, SizingPercentage, str, Sizing
]
Any value accepted where a Sizing is expected — see Sizing.parse
for the full list of accepted forms.
SizingKeyword and SizingPercentage are folded in ahead of the bare
str so editors surface the common values as completions; arbitrary strings
("1fr", "1/3", "37.5%") still typecheck via str.
FrameTitlePosition
module-attribute
¶
The side of a frame to display its title on.
Values
"top", "bottom".
KnownKeyboardBinding
module-attribute
¶
KnownKeyboardBinding: TypeAlias = Literal[
"ctrl+c",
"ctrl+d",
"ctrl+z",
"ctrl+x",
"ctrl+v",
"ctrl+a",
"ctrl+s",
"ctrl+w",
"ctrl+r",
"ctrl+f",
"ctrl+up",
"ctrl+down",
"ctrl+left",
"ctrl+right",
"shift+tab",
"shift+up",
"shift+down",
"shift+left",
"shift+right",
"alt+enter",
"alt+backspace",
"alt+up",
"alt+down",
"alt+left",
"alt+right",
]
Commonly used keybindings accepted by @on_keyboard.
KeyboardModifier
module-attribute
¶
A modifier key held alongside the primary action key.
KeyboardKey
module-attribute
¶
KeyboardKey: TypeAlias = Literal[
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"enter",
"esc",
"backspace",
"tab",
"backtab",
"up",
"down",
"left",
"right",
"home",
"end",
"pageup",
"pagedown",
"insert",
"delete",
"space",
"null",
"capslock",
"scrolllock",
"numlock",
"printscreen",
"pause",
"menu",
"keypadbegin",
"media",
"f1",
"f2",
"f3",
"f4",
"f5",
"f6",
"f7",
"f8",
"f9",
"f10",
"f11",
"f12",
"other",
]
Standard character/named keys accepted by @on_keyboard.
KeyboardBinding
module-attribute
¶
KeyboardBinding: TypeAlias = Union[
KnownKeyboardBinding, KeyboardKey, str
]
A keyboard binding: a primary key optionally preceded by +-joined
modifiers ("ctrl+a", "shift+tab", "alt+enter",
"ctrl+shift+z", ...).
MouseButton
module-attribute
¶
The mouse button that triggered a mouse event.
Area
dataclass
¶
Rectangular region of a cell grid.
Attributes:
-
x(int) –Left column.
-
y(int) –Top row.
-
width(int) –Width in cells.
-
height(int) –Height in cells.
Methods:
-
contains–Return whether
coordinatelies inside this area. -
fit_content–Fit a measured size inside this area on both axes.
contains
¶
contains(coordinate: Coordinate) -> bool
Return whether coordinate lies inside this area.
fit_content
¶
fit_content(
content: Size,
horizontal: "Alignment | None" = None,
vertical: "VerticalAlignment | None" = None,
) -> "Area"
Fit a measured size inside this area on both axes.
Parameters:
-
content(Size) –Measured content size, clamped to this area.
-
horizontal('Alignment | None', default:None) –Horizontal placement (default
"left"). -
vertical('VerticalAlignment | None', default:None) –Vertical placement (default
"top").
Returns:
-
'Area'–The fitted, aligned area.
Source code in xnano/area.py
Padding
dataclass
¶
Padding around a rectangular area.
Attributes:
-
top(int) –Cells above the content.
-
right(int) –Cells to the right of the content.
-
bottom(int) –Cells below the content.
-
left(int) –Cells to the left of the content.
Examples:
Methods:
-
parse–Normalize a padding value.
parse
classmethod
¶
parse(padding: PaddingLike | None) -> 'Padding'
Normalize a padding value.
Source code in xnano/area.py
Size
dataclass
¶
Resolved width and height in cells.
Attributes:
Methods:
-
from_tuple–Create a size from
(width, height). -
from_int–Create a square size.
from_tuple
classmethod
¶
Sizing
dataclass
¶
Sizing(
kind: SizingKind,
value: int = 0,
denominator: int = 1,
minimum: int | None = None,
maximum: int | None = None,
)
Single-axis layout size.
Attributes:
-
kind(SizingKind) –Sizing strategy.
-
value(int) –Cell count, percentage, numerator, or fill weight.
-
denominator(int) –Denominator for ratio sizing.
-
minimum(int | None) –Optional minimum cell count.
-
maximum(int | None) –Optional maximum cell count.
Examples:
Methods:
-
cells–Create a fixed cell size.
-
percent–Create a percentage of the available length.
-
ratio–Create a ratio of the available length.
-
fraction–Create a proportional fill size.
-
fit–Create a content-measured size.
-
with_bounds–Return this size with new cell bounds.
-
resolve–Resolve this size to cells.
-
parse–Normalize a supported sizing value.
value
class-attribute
instance-attribute
¶
value: int = 0
Cell count, percentage, numerator, or fill weight.
minimum
class-attribute
instance-attribute
¶
minimum: int | None = None
Optional minimum cell count.
maximum
class-attribute
instance-attribute
¶
maximum: int | None = None
Optional maximum cell count.
percent
classmethod
¶
percent(percentage: float) -> 'Sizing'
Create a percentage of the available length.
ratio
classmethod
¶
Create a ratio of the available length.
fit
classmethod
¶
with_bounds
¶
Return this size with new cell bounds.
resolve
¶
Resolve this size to cells.
Source code in xnano/types.py
parse
classmethod
¶
Normalize a supported sizing value.
Source code in xnano/types.py
Frame
dataclass
¶
Frame(
*,
background: "ColorLike | None" = None,
border: Border | None = None,
border_color: "ColorLike | None" = None,
border_sides: list[Side] | None = None,
title: str | None = None,
title_position: FrameTitlePosition | None = None,
padding: PaddingLike | None = None
)
Border, title, background, and padding around content.
Attributes:
-
background('ColorLike | None') –Fill color.
-
border(Border | None) –Border style.
-
border_color('ColorLike | None') –Border color.
-
border_sides(list[Side] | None) –Sides to draw.
-
title(str | None) –Border title.
-
title_position(FrameTitlePosition | None) –Title edge.
-
padding(PaddingLike | None) –Inner padding.
Methods:
-
is_empty–Return whether this frame has no visible attributes.
border_color
class-attribute
instance-attribute
¶
Border color.
border_sides
class-attribute
instance-attribute
¶
Sides to draw.
title_position
class-attribute
instance-attribute
¶
title_position: FrameTitlePosition | None = None
Title edge.
FieldFocus
dataclass
¶
ScrollHandle
dataclass
¶
Mutable scroll state for a field.
Attributes:
-
group(str) –Field group controlling this scroll region.
-
axis(Axis) –Scroll axis.
-
offset(int) –Current cell offset.
-
follow(bool) –Whether new content keeps the viewport at the end.
Methods:
-
scroll–Move the offset by
deltacells. -
scroll_to–Set the offset in cells.
-
scroll_to_end–Follow the end of the content.
align_area
¶
align_area(
outer: Area,
width: int,
height: int,
*,
horizontal: "Alignment | None" = None,
vertical: "VerticalAlignment | None" = None
) -> Area
Place a width x height box inside outer on both axes.
None on an axis anchors to its leading edge.
Parameters:
-
outer(Area) –The area to place the box within.
-
width(int) –Box width, clamped to
outer. -
height(int) –Box height, clamped to
outer. -
horizontal('Alignment | None', default:None) –Horizontal placement (default
"left"). -
vertical('VerticalAlignment | None', default:None) –Vertical placement (default
"top").
Returns:
-
Area–The placed area, always inside
outer.
Source code in xnano/area.py
resolve_flex_weight
¶
Return the numeric layout weight represented by flex.
field_has_frame_chrome
¶
Return whether a field defines structural frame styling.
field_fills_background
¶
Return whether a field paints its background across the whole slot.
A fill value takes precedence when set; otherwise a field with a
background fills its slot by default (fill=False opts out and
reverts to the accent-behind-glyphs behavior).
Source code in xnano/types.py
frame_from_field
¶
Build frame styling from a field definition.
Source code in xnano/types.py
is_grid
¶
Return whether a value is a grid instance.
Reads the __xnano_grid__ marker rather than importing
BaseGrid, so layers below the public DSL can ask this without a
circular import.
Source code in xnano/types.py
is_component
¶
uses_default_component_size
¶
Return whether a component uses the default layout size.