xnano.core
xnano.core
¶
xnano.core
Run interfaces live or offscreen and inspect their rendered frames.
Modules:
-
content–xnano.core.content
-
controller–xnano.core.controller
-
demo–xnano.core.demo
-
dispatch–xnano.core.dispatch
-
effects–xnano.core.effects
-
exceptions–xnano.core.exceptions
-
frame–xnano.core.frame
-
interface–xnano.core.interface
-
layout–xnano.core.layout
-
rendering–xnano.core.rendering
-
runtime–xnano.core.runtime
-
stage–xnano.core.stage
Classes:
-
Exit–Request that the active runtime stop.
-
HookError–Report a hook failure while preserving its original cause.
-
Frame–Immutable snapshot of one painted native frame.
-
Runtime–Drive one application through an
xnano_coresession. -
Cursor–Show, hide, style, and move the caret for a
Runtimesession. -
Device–Control device settings for a
Runtimesession.
Functions:
-
get_active_runtime–Return the runtime active in the current context.
Exit
¶
HookError
¶
HookError(hook_name: str, cause: BaseException)
Bases: RuntimeError
Report a hook failure while preserving its original cause.
Source code in xnano/core/exceptions.py
Frame
dataclass
¶
Frame(
width: int,
height: int,
text: str = "",
ansi: str = "",
cursor_position: tuple[int, int] | None = None,
cursor_visible: bool = True,
cursor_style: str | None = None,
title: str | None = None,
commands: tuple[Mapping[str, Any], ...] = (),
revision: int = 0,
)
Immutable snapshot of one painted native frame.
Example
Frame(width=20, height=4, text="Ready")
Attributes:
-
width(int) –Frame width in cells.
-
height(int) –Frame height in cells.
-
text(str) –Plain-text rows joined by newlines.
-
ansi(str) –ANSI-styled serialization of the buffer.
-
cursor_position(tuple[int, int] | None) –(x, y)caret cell, when known. -
cursor_visible(bool) –Whether the caret is shown.
-
cursor_style(str | None) –Caret style name when known.
-
title(str | None) –Terminal / document title when set.
-
commands(tuple[Mapping[str, Any], ...]) –Device commands queued with this frame.
-
revision(int) –Monotonic revision for diff consumers.
Methods:
-
contains–Return whether plain text contains
needle.
cursor_position
class-attribute
instance-attribute
¶
Caret position in cells.
cursor_visible
class-attribute
instance-attribute
¶
cursor_visible: bool = True
Whether the caret is visible.
cursor_style
class-attribute
instance-attribute
¶
cursor_style: str | None = None
Caret shape and blink style.
commands
class-attribute
instance-attribute
¶
Device commands emitted with the frame.
Runtime
¶
Runtime(
session: CoreSession,
*,
live: bool,
state: StateT | None = None,
title: str | None = None,
surface: str = "terminal",
tick_interval: int = 16
)
Bases: Generic[StateT]
Drive one application through an xnano_core session.
Most applications use :class:xnano.terminal.Terminal; use
Runtime directly when you need explicit session ownership.
Attributes:
-
session(CoreSession) –Native session owned by the runtime.
-
terminal('Runtime[StateT]') –Compatibility name for this runtime.
-
surface(str) –Presentation surface name.
-
is_live(bool) –Whether the runtime owns the user's terminal.
-
state(StateT | None) –Application state shared with hooks.
-
device(Device) –Display controls for the session.
-
cursor(Cursor) –Cursor controls for the session.
-
actions(Actions) –Synthetic action performer.
-
stage(Stage) –Current layout stage, when available.
-
size(tuple[int, int]) –Viewport width and height in cells.
-
focused_group(str | None) –Name of the focused field group.
Example
runtime = Runtime.offscreen(24, 3) frame = runtime.render("Hello") frame.width, frame.height (24, 3) runtime.close()
Methods:
-
live–Create a runtime backed by the active terminal.
-
offscreen–Create an active in-memory runtime.
-
supports_live_terminal–Return whether this build can claim a live terminal.
-
enter–Bind this runtime to the current context.
-
close–Restore the native session and release the active binding.
-
set_root–Set the renderable used by subsequent empty renders.
-
render–Render one frame and return its immutable snapshot.
-
call_soon–Schedule
callbackto run on the UI thread before the next pump. -
pump–Poll and dispatch at most one event.
-
dispatch–Dispatch one event to the root grid or component.
-
play_effect–Play an effect over fields recorded by the latest render.
-
cancel_effect–Stop the effect registered under
key. -
is_animating–Whether any effect is currently running in this session.
-
perform–Perform a synthetic action through its event representation.
-
resize–Resize support is fixed at offscreen-session construction.
-
request_exit–Stop the run loop after the current dispatch.
-
focus–Focus a named field group.
-
blur–Clear field focus.
-
focus_next–Move focus through the root grid when supported.
-
focus_previous–Move focus backward through the root grid when supported.
-
get_output–Return the current buffer as plain text.
-
get_output_as_ansi–Return the current buffer with ANSI styling.
Source code in xnano/core/runtime.py
terminal
property
¶
Compatibility name for the runtime's terminal surface.
live
classmethod
¶
live(
*,
state: StateT | None = None,
title: str | None = None,
tick_interval: int = 16,
mouse_events: bool = False
) -> "Runtime[StateT]"
Create a runtime backed by the active terminal.
Source code in xnano/core/runtime.py
offscreen
classmethod
¶
offscreen(
width: int = 80,
height: int = 24,
*,
state: StateT | None = None,
title: str | None = None
) -> "Runtime[StateT]"
Create an active in-memory runtime.
Source code in xnano/core/runtime.py
enter
¶
Bind this runtime to the current context.
close
¶
Restore the native session and release the active binding.
Source code in xnano/core/runtime.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
Render one frame and return its immutable snapshot.
Source code in xnano/core/runtime.py
call_soon
¶
Schedule callback to run on the UI thread before the next pump.
Thread-safe: worker threads enqueue here and the runtime drains the queue on its own thread, so background work can mutate grid state without racing the renderer.
Source code in xnano/core/runtime.py
pump
¶
Poll and dispatch at most one event.
Source code in xnano/core/runtime.py
dispatch
¶
dispatch(event: Any) -> None
Dispatch one event to the root grid or component.
Source code in xnano/core/runtime.py
play_effect
¶
Play an effect over fields recorded by the latest render.
Parameters:
-
effect(Any) –Effect description.
-
fields(list[str] | None, default:None) –Field names whose rendered areas receive the effect.
-
repeat(bool, default:False) –Loop the effect until it is cancelled, instead of running once for its duration.
Returns:
-
list[str]–The session keys registered, one per field that had a
-
list[str]–rendered area. Empty when nothing was targeted.
Source code in xnano/core/runtime.py
perform
¶
perform(action: Any) -> None
Perform a synthetic action through its event representation.
Source code in xnano/core/runtime.py
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | |
resize
¶
Resize support is fixed at offscreen-session construction.
request_exit
¶
focus
¶
Focus a named field group.
Source code in xnano/core/runtime.py
blur
¶
Cursor
¶
Show, hide, style, and move the caret for a Runtime session.
Obtained from runtime.cursor — do not construct this class
yourself.
Attributes:
-
visible(bool) –Whether the caret is shown.
-
style(CursorStyle) –Caret rendering style.
-
position(Coordinate) –Current
(x, y)position in cells.
Example
from xnano.core.runtime import Runtime runtime = Runtime.offscreen(20, 4) runtime.cursor.position = (3, 1) runtime.cursor.position (3, 1) runtime.close()
Methods:
-
get_position–The locally tracked
(x, y)caret position. -
move–Move the caret to
(x, y). -
move_up–Move the caret up by
countrows. -
move_down–Move the caret down by
countrows. -
move_left–Move the caret left by
countcolumns. -
move_right–Move the caret right by
countcolumns. -
save–Save the current caret position.
-
restore–Restore the previously saved caret position.
-
enable_blinking–Enable caret blinking.
-
disable_blinking–Disable caret blinking.
Source code in xnano/cursor.py
get_position
¶
get_position() -> Coordinate
move
¶
save
¶
restore
¶
Restore the previously saved caret position.
enable_blinking
¶
Enable caret blinking.
Source code in xnano/cursor.py
disable_blinking
¶
Disable caret blinking.
Source code in xnano/cursor.py
Device
¶
Control device settings for a Runtime session.
Title, clear, size, scroll, clipboard, raw mode, alternate screen,
mouse capture, and related flags. Obtained from runtime.device
— do not construct this class yourself.
Attributes:
-
raw_mode(bool) –Whether raw input mode is enabled.
-
alternate_screen(bool) –Whether the alternate screen buffer is active.
-
line_wrap(bool) –Whether automatic line wrapping is enabled.
-
mouse_capture(bool) –Whether mouse events are captured.
-
bracketed_paste(bool) –Whether bracketed paste mode is enabled.
-
focus_change(bool) –Whether terminal focus events are enabled.
-
synchronized_updates(bool) –Whether synchronized updates are enabled.
-
title(str | None) –Window or page title.
-
size(Size) –Current viewport size in cells.
Example
from xnano.core.runtime import Runtime runtime = Runtime.offscreen(20, 4, title="Example") runtime.device.size.width 20 runtime.close()
Methods:
-
clear–Clear the terminal display.
-
scroll_up–Scroll the viewport up by
lines. -
scroll_down–Scroll the viewport down by
lines. -
copy_to_clipboard–Copy
textto the clipboard when supported.
Source code in xnano/device.py
alternate_screen
property
writable
¶
alternate_screen: bool
Whether the alternate screen buffer is active.
focus_change
property
writable
¶
focus_change: bool
Whether OS-level terminal focus change events are enabled.
synchronized_updates
property
writable
¶
synchronized_updates: bool
Whether synchronized output updates are enabled.