xnano.core.runtime
xnano.core.runtime
¶
xnano.core.runtime
Own live and offscreen sessions, rendering, events, state, focus, and output.
Classes:
-
Runtime–Drive one application through an
xnano_coresession.
Functions:
-
get_active_runtime–Return the runtime active in the current context.
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.