xnano.device
xnano.device
¶
xnano.device
Control the title, display modes, clipboard, and viewport of a runtime.
Flags and title are always tracked locally, so device behaves the
same for a live or an offscreen runtime (tests, and every web visitor's
session). Only a live runtime issues the real terminal escape codes;
an offscreen runtime must not, or it would write control sequences to
whatever process owns stdout (wrong for a headless web server) — and
enable_raw_mode raises OSError outright when there is no real
terminal to configure.
Classes:
-
Device–Control device settings for a
Runtimesession.
Attributes:
ClearType
module-attribute
¶
ClearType: TypeAlias = Literal[
"all",
"purge",
"from_cursor_down",
"from_cursor_up",
"current_line",
"until_new_line",
]
How much of the terminal display Device.clear should erase.
Values
"all": The entire visible screen.
"purge": The screen and its scrollback history.
"from_cursor_down": From the caret to the bottom of the screen.
"from_cursor_up": From the top of the screen to the caret.
"current_line": Only the caret's current line.
"until_new_line": From the caret to the end of its line.
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.