xnano.terminal
xnano.terminal
¶
xnano.terminal
Run grids and components in live or offscreen terminal sessions.
Classes:
-
Terminal–Paint and interact with an application in a terminal.
Terminal
¶
Terminal(
*,
state: StateT | None = None,
title: str | None = None,
tick_interval: int = 16,
mouse_events: bool = False
)
Bases: Generic[StateT]
Paint and interact with an application in a terminal.
Terminal selects a live session when one is available and otherwise
uses an offscreen buffer. Use :meth:offscreen explicitly in tests.
Pass mouse_events=True to receive clicks, drags, hovers, and wheel
events — required for click-to-focus and @on_click/@on_mouse
hooks; it is off by default so a keyboard-only app pays nothing.
Attributes:
-
runtime(Runtime[StateT]) –Runtime owned by the terminal.
-
state(StateT | None) –Application state shared with event hooks.
-
device–Display controls for the active session.
-
cursor–Cursor controls for the active session.
-
actions–Synthetic action performer.
-
stage–Layout stage for the current root.
-
size(tuple[int, int]) –Viewport width and height in cells.
-
focused_group(str | None) –Name of the focused field group.
-
surface–Active presentation surface.
Example
terminal = Terminal.offscreen(cols=24, rows=3) frame = terminal.render("Hello, xnano") "Hello, xnano" in frame.text True terminal.close()
Methods:
-
offscreen–Create a terminal backed by an in-memory cell buffer.
-
supports_live_terminal–Return whether interactive terminal sessions are available.
-
attach_grid–Set the grid used by subsequent renders and dispatch.
-
render–Paint one frame and return its immutable snapshot.
-
run–Render and dispatch events until an exit is requested.
-
request_exit–Stop the active run loop.
-
focus–Focus a named field group.
-
blur–Clear field focus.
-
focus_next–Move focus forward.
-
focus_previous–Move focus backward.
-
get_output–Return the current cell buffer as plain text.
-
get_output_as_ansi–Return the current cell buffer with ANSI styling.
-
copy_to_clipboard–Copy text when the active platform supports clipboard writes.
-
close–Restore and release the owned runtime.
Source code in xnano/terminal.py
offscreen
classmethod
¶
offscreen(
*,
cols: int = 40,
rows: int = 12,
state: StateT | None = None,
title: str | None = None
) -> "Terminal[StateT]"
Create a terminal backed by an in-memory cell buffer.
Source code in xnano/terminal.py
render
¶
render(
*renderables: Any,
foreground: ColorLike | None = None,
background: ColorLike | None = None,
modifiers: Sequence[CharacterModifier] | 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,
gap: int = 0,
direction: Direction = "vertical",
color: ColorLike | None = None,
align: Alignment | None = None
) -> Frame
Paint one frame and return its immutable snapshot.
Parameters:
-
*renderables(Any, default:()) –Grids, components, content primitives, or plain values to paint.
-
foreground(ColorLike | None, default:None) –Foreground color applied to plain values.
-
background(ColorLike | None, default:None) –Background color for the rendered area.
-
modifiers(Sequence[CharacterModifier] | None, default:None) –Character modifiers applied to plain values.
-
horizontal_align(Alignment | None, default:None) –Horizontal alignment applied to plain values.
vertical_align: Vertical alignment applied to plain values. border: Border style around the rendered area. border_sides: Border sides to draw. border_color: Border foreground color. title: Optional border title. title_position: Border edge that holds the title. padding: Space between the border and content. gap: Cells between multiple renderables. direction: Direction used to lay out multiple renderables.
Returns:
-
Frame–A snapshot of the rendered terminal frame.
Source code in xnano/terminal.py
run
¶
run(
*renderables: Any,
foreground: ColorLike | None = None,
background: ColorLike | None = None,
modifiers: Sequence[CharacterModifier] | 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,
gap: int = 0,
direction: Direction = "vertical",
color: ColorLike | None = None,
align: Alignment | None = None
) -> None
Render and dispatch events until an exit is requested.
Parameters:
-
*renderables(Any, default:()) –Grids, components, content primitives, or plain values to paint.
-
foreground(ColorLike | None, default:None) –Foreground color applied to plain values.
-
background(ColorLike | None, default:None) –Background color for the rendered area.
-
modifiers(Sequence[CharacterModifier] | None, default:None) –Character modifiers applied to plain values.
-
horizontal_align(Alignment | None, default:None) –Horizontal alignment applied to plain values.
vertical_align: Vertical alignment applied to plain values. border: Border style around the rendered area. border_sides: Border sides to draw. border_color: Border foreground color. title: Optional border title. title_position: Border edge that holds the title. padding: Space between the border and content. gap: Cells between multiple renderables. direction: Direction used to lay out multiple renderables.