pub struct Screen<I, O>{ /* private fields */ }Expand description
A self-managing terminal application facade composing a Terminal,
a cell-diff renderer, and an EventSource with the non-render terminal and
input modes. See the module documentation for the lifecycle.
Screen is Send and Sync whenever its input and output handles are,
so it can be moved onto another thread or held across an .await point in a
multi-threaded async runtime.
Implementations§
Source§impl<I: Input, O: Write> Screen<I, O>
impl<I: Input, O: Write> Screen<I, O>
Sourcepub fn set_cursor_style(
&mut self,
shape: CursorShape,
blinking: bool,
) -> Result<()>
pub fn set_cursor_style( &mut self, shape: CursorShape, blinking: bool, ) -> Result<()>
Sourcepub fn set_pointer_shape(&mut self, shape: &str) -> Result<()>
pub fn set_pointer_shape(&mut self, shape: &str) -> Result<()>
Set the pointer (mouse cursor) shape (OSC 22) and flush.
shape is a pointer shape name such as "default", "text", or
"pointer". The shape is recorded for save/restore.
Sourcepub fn reset_pointer_shape(&mut self) -> Result<()>
pub fn reset_pointer_shape(&mut self) -> Result<()>
Reset the pointer (mouse cursor) shape to the terminal default
(OSC 22 ; default) and flush.
Uses the explicit "default" shape name rather than an empty one: some
terminals don’t treat an empty OSC 22 as a reset.
Sourcepub fn enable_mouse(&mut self, tracking: MouseTracking) -> Result<()>
pub fn enable_mouse(&mut self, tracking: MouseTracking) -> Result<()>
Enable mouse tracking and flush.
This emits exactly what is asked for and does not consult terminal
capabilities. Unsupported modes are ignored by
the terminal, and because the mode requests are mutually exclusive, each
terminal settles on the most capable variant it understands:
- Tracking: button (
1000) and button-event (1002) are always requested, so a terminal reports drag where it can and plain clicks otherwise. WithMouseTracking::MOTION, any-event tracking (1003) is added on top, so motion without a button held is reported where supported. - Encoding: SGR (
1006) is always requested, since the legacy byte encoding caps coordinates at 223 and SGR is universally supported. WithMouseTracking::PIXELS, SGR-pixel (1016) is added; terminals that support it report pixel coordinates, and the rest fall back to SGR cell coordinates.
Pass MouseTracking::empty() for basic button tracking with no
extras. To turn mouse tracking off, call disable_mouse.
To learn which variant a terminal actually chose, read
capabilities (for example
mouse_sgr_pixel to tell
whether pixels or cells will arrive). When pixel reporting is active, a
Mouse event’s pixel coordinates can be converted
to cells with mouse_pixels_to_cells.
The request is recorded for save/restore.
Sourcepub fn disable_mouse(&mut self) -> Result<()>
pub fn disable_mouse(&mut self) -> Result<()>
Disable all mouse tracking modes and encodings, and flush.
Sourcepub fn enable_bracketed_paste(&mut self) -> Result<()>
pub fn enable_bracketed_paste(&mut self) -> Result<()>
Enable bracketed paste mode (DEC private mode 2004) and flush.
Sourcepub fn disable_bracketed_paste(&mut self) -> Result<()>
pub fn disable_bracketed_paste(&mut self) -> Result<()>
Disable bracketed paste mode (DEC private mode 2004) and flush.
Sourcepub fn enable_focus_events(&mut self) -> Result<()>
pub fn enable_focus_events(&mut self) -> Result<()>
Enable focus in/out reporting (DEC private mode 1004) and flush.
Sourcepub fn disable_focus_events(&mut self) -> Result<()>
pub fn disable_focus_events(&mut self) -> Result<()>
Disable focus in/out reporting (DEC private mode 1004) and flush.
Sourcepub fn enable_color_scheme_updates(&mut self) -> Result<()>
pub fn enable_color_scheme_updates(&mut self) -> Result<()>
Enable color-scheme update notifications (DEC private mode 2031) and
flush. The terminal then sends a CSI ? 997 ; {1|2} n report
whenever the user or operating system switches between dark and
light schemes; these surface as Event::ColorScheme. The report
indicates only the dark/light preference, not the actual colors.
Sourcepub fn disable_color_scheme_updates(&mut self) -> Result<()>
pub fn disable_color_scheme_updates(&mut self) -> Result<()>
Disable color-scheme update notifications (DEC private mode 2031) and flush.
Sourcepub fn enable_in_band_resize(&mut self) -> Result<()>
pub fn enable_in_band_resize(&mut self) -> Result<()>
Enable in-band resize notifications (DEC private mode 2048) and
flush. The terminal then reports every surface size change in-band
as a CSI 48 ; height ; width ; ypixel ; xpixel t sequence, which
the decoder surfaces as Event::Resize — no SIGWINCH handler
required.
Sourcepub fn disable_in_band_resize(&mut self) -> Result<()>
pub fn disable_in_band_resize(&mut self) -> Result<()>
Disable in-band resize notifications (DEC private mode 2048) and flush.
Sourcepub fn set_title(&mut self, title: &str) -> Result<()>
pub fn set_title(&mut self, title: &str) -> Result<()>
Set both the window title and icon name (OSC 0) and flush.
An empty title clears both overrides, restoring the terminal’s
defaults; the state is recorded as unset so teardown and resume skip
them. To set just one, use
set_window_title (OSC 2) or
set_icon_title (OSC 1).
Sourcepub fn set_window_title(&mut self, title: &str) -> Result<()>
pub fn set_window_title(&mut self, title: &str) -> Result<()>
Set the window title only (OSC 2) and flush.
An empty title clears the override, restoring the terminal’s default
window title. Unlike set_title (OSC 0), this
leaves the icon name untouched.
Sourcepub fn set_icon_title(&mut self, title: &str) -> Result<()>
pub fn set_icon_title(&mut self, title: &str) -> Result<()>
Set the icon name only (OSC 1) and flush.
An empty title clears the override, restoring the terminal’s default
icon name. Unlike set_title (OSC 0), this leaves
the window title untouched.
Sourcepub fn set_modify_other_keys(&mut self, mode: ModifyOtherKeysMode) -> Result<()>
pub fn set_modify_other_keys(&mut self, mode: ModifyOtherKeysMode) -> Result<()>
Set the xterm modifyOtherKeys mode (CSI > 4 ; n m) and flush.
Passing ModifyOtherKeysMode::Disabled resets it (CSI > 4 m).
The mode is recorded so Screen::finish
can reset it and Screen::resume re-apply
it.
Sourcepub fn set_foreground_color(&mut self, color: Color) -> Result<()>
pub fn set_foreground_color(&mut self, color: Color) -> Result<()>
Set the default foreground color (OSC 10) and flush. The color is
converted to 24-bit RGB and emitted as rgb:RRRR/GGGG/BBBB, and is
recorded so Screen::finish can restore
the terminal default and Screen::resume
can re-apply it.
Sourcepub fn reset_foreground_color(&mut self) -> Result<()>
pub fn reset_foreground_color(&mut self) -> Result<()>
Restore the terminal’s default foreground color (OSC 110) and
flush.
Sourcepub fn set_background_color(&mut self, color: Color) -> Result<()>
pub fn set_background_color(&mut self, color: Color) -> Result<()>
Set the default background color (OSC 11) and flush. See
set_foreground_color for
state-tracking semantics.
Sourcepub fn reset_background_color(&mut self) -> Result<()>
pub fn reset_background_color(&mut self) -> Result<()>
Restore the terminal’s default background color (OSC 111) and
flush.
Sourcepub fn set_cursor_color(&mut self, color: Color) -> Result<()>
pub fn set_cursor_color(&mut self, color: Color) -> Result<()>
Set the cursor color (OSC 12) and flush. See
set_foreground_color for
state-tracking semantics.
Sourcepub fn reset_cursor_color(&mut self) -> Result<()>
pub fn reset_cursor_color(&mut self) -> Result<()>
Restore the terminal’s default cursor color (OSC 112) and flush.
Sourcepub fn set_palette_color(&mut self, index: u8, color: Color) -> Result<()>
pub fn set_palette_color(&mut self, index: u8, color: Color) -> Result<()>
Set a terminal palette color by index (OSC 4) and flush. The
override is tracked so Screen::finish can
restore it and Screen::resume re-apply it.
Sourcepub fn reset_palette_color(&mut self, index: u8) -> Result<()>
pub fn reset_palette_color(&mut self, index: u8) -> Result<()>
Reset a single terminal palette color to its default
(OSC 104 ; index) and flush.
Sourcepub fn reset_palette_colors(&mut self) -> Result<()>
pub fn reset_palette_colors(&mut self) -> Result<()>
Reset the entire terminal palette to its defaults (OSC 104) and
flush, clearing every tracked palette override.
Sourcepub fn request_window_pixel_size(&mut self) -> Result<()>
pub fn request_window_pixel_size(&mut self) -> Result<()>
Request the window size in pixels (XTWINOPS CSI 14 t). Reply:
Event::WindowPixelSize.
Sourcepub fn request_cell_pixel_size(&mut self) -> Result<()>
pub fn request_cell_pixel_size(&mut self) -> Result<()>
Request the character cell size in pixels (XTWINOPS CSI 16 t).
Reply: Event::CellPixelSize.
Sourcepub fn request_kitty_keyboard(&mut self) -> Result<()>
pub fn request_kitty_keyboard(&mut self) -> Result<()>
Request the terminal’s active Kitty keyboard flags (CSI ? u).
The reply is recorded in capabilities.
Sourcepub fn request_modify_other_keys(&mut self) -> Result<()>
pub fn request_modify_other_keys(&mut self) -> Result<()>
Request the terminal’s modifyOtherKeys state (CSI ? 4 m). The
reply is recorded in capabilities.
Sourcepub fn request_foreground_color(&mut self) -> Result<()>
pub fn request_foreground_color(&mut self) -> Result<()>
Request the default foreground color (OSC 10 ; ? ST). Reply:
Event::ForegroundColor.
Sourcepub fn request_background_color(&mut self) -> Result<()>
pub fn request_background_color(&mut self) -> Result<()>
Request the default background color (OSC 11 ; ? ST). Reply:
Event::BackgroundColor.
Sourcepub fn request_cursor_color(&mut self) -> Result<()>
pub fn request_cursor_color(&mut self) -> Result<()>
Request the cursor color (OSC 12 ; ? ST). Reply:
Event::CursorColor.
Sourcepub fn request_palette_color(&mut self, index: u8) -> Result<()>
pub fn request_palette_color(&mut self, index: u8) -> Result<()>
Request a terminal palette color by index (OSC 4 ; index ; ? ST).
Reply: OSC 4 ; index ; rgb:... ST.
Sourcepub fn request_mode(&mut self, mode: Mode) -> Result<()>
pub fn request_mode(&mut self, mode: Mode) -> Result<()>
Request a terminal mode’s current setting (DECRQM). Reply:
Event::ModeReport.
The reply’s ModeSetting reports whether
the mode is set, reset, or permanently fixed. A permanently reset mode
is recognized but can never be enabled, so check
ModeSetting::is_available
before relying on it.
Sourcepub fn request_cursor_position(&mut self) -> Result<()>
pub fn request_cursor_position(&mut self) -> Result<()>
Request the cursor position (CSI 6 n). Reply:
Event::CursorPosition.
Sourcepub fn request_color_scheme(&mut self) -> Result<()>
pub fn request_color_scheme(&mut self) -> Result<()>
Request the current color scheme (CSI ? 996 n): whether the
terminal’s scheme is dark or light. This reports only the dark/light
preference, not the actual colors. Reply:
Event::ColorScheme.
Sourcepub fn set_system_clipboard(&mut self, data: &[u8]) -> Result<()>
pub fn set_system_clipboard(&mut self, data: &[u8]) -> Result<()>
Set the system clipboard contents (OSC 52 ; c). data is
base64-encoded for transport.
Sourcepub fn set_primary_clipboard(&mut self, data: &[u8]) -> Result<()>
pub fn set_primary_clipboard(&mut self, data: &[u8]) -> Result<()>
Set the primary selection contents (OSC 52 ; p). data is
base64-encoded for transport.
Sourcepub fn request_system_clipboard(&mut self) -> Result<()>
pub fn request_system_clipboard(&mut self) -> Result<()>
Request the system clipboard contents (OSC 52 ; c ; ?). Reply:
Event::Clipboard.
Sourcepub fn request_primary_clipboard(&mut self) -> Result<()>
pub fn request_primary_clipboard(&mut self) -> Result<()>
Request the primary selection contents (OSC 52 ; p ; ?). Reply:
Event::Clipboard.
Source§impl<I, O> Screen<I, O>
impl<I, O> Screen<I, O>
Sourcepub fn set_cell(&mut self, pos: impl Into<Position>, cell: &Cell)
pub fn set_cell(&mut self, pos: impl Into<Position>, cell: &Cell)
Write cell at pos in the desired frame.
Sourcepub fn cell_mut(&mut self, pos: impl Into<Position>) -> Option<&mut Cell>
pub fn cell_mut(&mut self, pos: impl Into<Position>) -> Option<&mut Cell>
Borrow the cell at pos mutably, marking its columns touched.
Sourcepub fn render(&mut self) -> Result<()>
pub fn render(&mut self) -> Result<()>
Diff the staged frame against the tracked terminal, stage the minimal escape bytes, and flush them through the terminal.
When a declarative cursor rest position has been staged with
set_cursor_position, the cursor is moved
there at the end of the frame, inside the same hide/synchronized-output
bracket as the cell diff, so it lands atomically and without flicker.
Sourcepub fn invalidate(&mut self)
pub fn invalidate(&mut self)
Force a full redraw on the next render.
Sourcepub fn resize(&mut self, size: impl Into<Size>)
pub fn resize(&mut self, size: impl Into<Size>)
Resize the managed area. In fullscreen pass the terminal viewport size; inline, the terminal width and the application surface height.
Sourcepub fn insert_above(&mut self, content: &str) -> Result<()>
pub fn insert_above(&mut self, content: &str) -> Result<()>
Insert content into the scrollback above the managed area and flush
it to the terminal. In inline mode this pushes the lines into the
terminal’s scrollback; in alternate-screen mode they go into the alt
screen’s hidden scrollback. The managed area is preserved in place, so
no redraw is needed and a following render sees no
change. An empty string is a no-op.
§Errors
Returns any error from flushing the inserted lines to the terminal.
Sourcepub fn move_cursor_to(&mut self, pos: impl Into<Position>) -> Result<()>
pub fn move_cursor_to(&mut self, pos: impl Into<Position>) -> Result<()>
Immediately move the terminal cursor to a buffer-relative position and flush. No-op when the renderer already reports the cursor there with both axes known.
This is imperative: the move is emitted and flushed now, independent of
render. It does not affect the declarative resting
position staged with set_cursor_position;
a subsequent render will snap the cursor back to that sticky position
if one is set. To change where frames leave the cursor, use
set_cursor_position instead.
Sourcepub fn move_cursor_by(&mut self, dx: i16, dy: i16) -> Result<()>
pub fn move_cursor_by(&mut self, dx: i16, dy: i16) -> Result<()>
Immediately move the terminal cursor relative to the tracked cursor and flush.
Convenience over move_cursor_to: the target
is the tracked cursor offset by (dx, dy), saturating at the buffer
origin. Like move_cursor_to, it does not clamp to the right or
bottom edge. An unknown tracked cursor is treated as the origin.
Sourcepub fn set_cursor_position(&mut self, pos: impl Into<Position>)
pub fn set_cursor_position(&mut self, pos: impl Into<Position>)
Stage a declarative resting position for the cursor, applied at the end
of every render.
This is the cursor analogue of set_cell: it stages
intent rather than emitting now. render leaves the terminal cursor at
the buffer-relative pos after each frame’s cell diff. Call
clear_cursor_position to stop steering
it and leave the cursor wherever the diff ended.
The position is sticky — it persists across frames and is re-applied
on every render (cheaply, as a no-op when the cursor is already there)
until you change or clear it. An app whose cursor follows content
(e.g. a text field) should call this each time that content moves.
Cursor visibility is orthogonal: this never shows or hides the cursor.
Use show_cursor / hide_cursor
for that. A position outside the managed area is clamped to its edges.
The argument is anything that converts into a Position, so a bare
(x, y) works:
let mut screen = uncurses::screen::Screen::open()?;
screen.set_cursor_position((4, 0)); // stage
screen.clear_cursor_position(); // stop steering itSourcepub fn clear_cursor_position(&mut self)
pub fn clear_cursor_position(&mut self)
Clear the staged cursor resting position, leaving the cursor wherever each frame’s cell diff ends.
Sourcepub fn tracked_cursor(&self) -> Option<Position>
pub fn tracked_cursor(&self) -> Option<Position>
The renderer’s tracked cursor: the buffer-relative cell where the
renderer believes the terminal cursor currently sits, or None when
that position is unknown (initially, after a screen reset, or after
invalidate_tracked_cursor). This
is bookkeeping, not a live cursor-position query.
Sourcepub fn invalidate_tracked_cursor(&mut self)
pub fn invalidate_tracked_cursor(&mut self)
Mark the tracked cursor position unknown, so the next staged move always emits rather than short-circuiting on a matching tracked position. Use after moving the terminal cursor by a means the renderer cannot see (e.g. a raw escape written directly).
Sourcepub fn set_tracked_cursor(&mut self, pos: impl Into<Position>)
pub fn set_tracked_cursor(&mut self, pos: impl Into<Position>)
Set the tracked cursor to buffer-relative pos, with both axes
known, without emitting any move. This only updates the renderer’s
belief; the caller must have already placed the terminal cursor there
(e.g. with a raw escape the renderer cannot see). For an actual cursor
move use move_cursor_to.
Sourcepub fn enter_alt_screen(&mut self) -> Result<()>
pub fn enter_alt_screen(&mut self) -> Result<()>
Enter the alternate screen and flush.
Sourcepub fn exit_alt_screen(&mut self) -> Result<()>
pub fn exit_alt_screen(&mut self) -> Result<()>
Leave the alternate screen and flush.
Sourcepub fn show_cursor(&mut self) -> Result<()>
pub fn show_cursor(&mut self) -> Result<()>
Show the cursor and flush.
Sourcepub fn hide_cursor(&mut self) -> Result<()>
pub fn hide_cursor(&mut self) -> Result<()>
Hide the cursor and flush.
Sourcepub fn set_synchronized_output(&mut self, enabled: bool)
pub fn set_synchronized_output(&mut self, enabled: bool)
Enable or disable synchronized-output frame wrapping.
When enabled, each non-empty render is wrapped in
begin/end synchronized-output sequences (DEC mode 2026) so terminals
that support it present the frame atomically, with no mid-frame
repaint. Terminals that don’t support 2026 ignore the markers.
This is your switch to flip: uncurses does not second-guess it against
detected capabilities. It is enabled automatically when the terminal
reports 2026 support during init, and you can override
that here at any time.
Enabling it also changes how the cursor is handled per frame. With sync off, a visible cursor is hidden around the cell diff so it doesn’t dance across cells as the renderer repositions it. With sync on, the frame is presented in one step, so that hide/show pair is dropped: it is redundant, and toggling the cursor every frame resets its blink phase, which reads as flicker.
This only sets state; the markers are emitted on the next render.
Sourcepub fn enable_grapheme_clusters(&mut self) -> Result<()>
pub fn enable_grapheme_clusters(&mut self) -> Result<()>
Enable Unicode core / grapheme-cluster mode (DECSET 2027) and flush:
set_str and
insert_above measure cell widths per extended
grapheme cluster (UTS-29 plus emoji presentation rules).
Sourcepub fn disable_grapheme_clusters(&mut self) -> Result<()>
pub fn disable_grapheme_clusters(&mut self) -> Result<()>
Disable grapheme-cluster mode (DECRST 2027) and flush, falling back to per-code-point wcwidth-style measurement.
Sourcepub fn set_kitty_keyboard(
&mut self,
flags: Option<KittyKeyboardFlags>,
) -> Result<()>
pub fn set_kitty_keyboard( &mut self, flags: Option<KittyKeyboardFlags>, ) -> Result<()>
Set the per-screen kitty keyboard enhancements and flush.
Some(flags) enables the selected progressive-enhancement bits;
None disables every enhancement.
Sourcepub fn set_color_profile(&mut self, profile: Profile)
pub fn set_color_profile(&mut self, profile: Profile)
Set the color profile used when emitting styled cells.
Sourcepub fn color_profile(&self) -> Profile
pub fn color_profile(&self) -> Profile
Return the color profile used when emitting styled cells.
This is the profile the renderer downsamples colors to, set by
set_color_profile or detected from the
environment when the screen was constructed. Pass it to
Encode::encode_with to serialize
a surface the same way this screen renders it.
Sourcepub fn set_optimizations(&mut self, optimizations: Optimizations)
pub fn set_optimizations(&mut self, optimizations: Optimizations)
Set the renderer optimization flags.
Sourcepub fn optimizations(&self) -> Optimizations
pub fn optimizations(&self) -> Optimizations
Return the renderer optimization flags currently in effect.
Sourcepub fn grapheme_clusters(&self) -> bool
pub fn grapheme_clusters(&self) -> bool
Return whether Unicode core / grapheme-cluster mode (DEC 2027) is
active. When true, text is measured per extended grapheme cluster;
when false, per code point (wcwidth-style).
Sourcepub fn poll_event(&self, timeout: Option<Duration>) -> Result<bool>
pub fn poll_event(&self, timeout: Option<Duration>) -> Result<bool>
Drive the input source for up to timeout, returning whether any
event became available. A pure readiness wait: no capability tracking.
See EventSource::poll.
Sourcepub fn try_read_event(&self) -> Option<Event>
pub fn try_read_event(&self) -> Option<Event>
Take the next queued event without doing I/O. A pure read: pass the
event to observe_event to keep capability
tracking alive. See EventSource::try_read.
Sourcepub fn read_event(&self) -> Result<Event>
pub fn read_event(&self) -> Result<Event>
Block until the next event. A pure read: pass the event to
observe_event to keep capability tracking
alive. See EventSource::read.
Sourcepub fn unread_event(&self, event: Event)
pub fn unread_event(&self, event: Event)
Return an event to the front of the input queue, so the next
read_event / try_read_event
yields it before anything already queued. See EventSource::unread.
Sourcepub fn event_source(&self) -> Arc<Mutex<EventSource<I>>>
pub fn event_source(&self) -> Arc<Mutex<EventSource<I>>>
A shared handle to the input source behind
read_event and friends, for driving input from a
separate reader over the same decoder rather than a second one racing
the same file descriptor.
The main use is async input: build an
EventStream with
EventStream::from_shared from
this handle and poll it on your executor. Like every read path, it is
pure — feed each event back through observe_event
to keep capability tracking alive.
Sharing one source between a live reader and the screen’s own
read_event is best-effort: an event goes to
whichever consumer drains it first, so pick one reader in steady state.
Sourcepub fn event_stream(&self) -> EventStream<I>where
I: 'static,
pub fn event_stream(&self) -> EventStream<I>where
I: 'static,
Build an async EventStream over this
screen’s input, for reading events with events.next().await inside a
select! on any executor. The stream shares the screen’s decoder, so it
does not race a second reader on the same file descriptor.
Reads are pure: feed each event to observe_event
to keep capability tracking alive, exactly as the sync path does. Read
through the stream or through read_event in
steady state, not both at once: a shared source hands each event to
whichever consumer drains it first.
Sourcepub fn capabilities(&self) -> Capabilities
pub fn capabilities(&self) -> Capabilities
Terminal capabilities detected so far from intercepted query
replies. Populated as the relevant reports arrive through the event
delegates after Self::init.
Sourcepub fn window_cells(&self) -> Option<Size>
pub fn window_cells(&self) -> Option<Size>
Last observed full terminal size in cells, cached from resize and
WindowCellSize reports as they flow through the event delegates.
None until one has been observed.
Sourcepub fn window_pixels(&self) -> Option<Size>
pub fn window_pixels(&self) -> Option<Size>
Last observed full terminal size in pixels, cached from resize
(when it carries pixel dimensions) and from
request_window_pixel_size
replies. None until one has been observed.
Sourcepub fn terminal_name(&self) -> Option<&str>
pub fn terminal_name(&self) -> Option<&str>
The raw XTVERSION reply identifying the terminal (e.g.
"XTerm(380)"). None until the reply has been observed.
Sourcepub fn mouse_pixels_to_cells(&self, mouse: Mouse) -> Option<Mouse>
pub fn mouse_pixels_to_cells(&self, mouse: Mouse) -> Option<Mouse>
Convert a Mouse event reported in pixel
coordinates (SGR-pixel encoding) to cell coordinates using the
cached terminal size. Returns None when the window pixel size has
not been observed yet, so no conversion is possible — request it
with request_window_pixel_size,
or rely on an in-band resize report to populate it.
Sourcepub fn observe_event(&mut self, event: &Event) -> Result<()>
pub fn observe_event(&mut self, event: &Event) -> Result<()>
Apply an event to the screen’s capability tracking. The event is inspected, never consumed.
Reads are pure: read_event,
try_read_event, and the async
event_stream all hand back events without
tracking capabilities. Pass every event you receive here — on both the
sync and async paths — so capability detection stays alive.
Capability-report replies to the queries init fires are
recorded into capabilities, window-size reports
update window_cells /
window_pixels, and the render-affecting reports
are applied. On the terminating Primary DA reply, the discovery-driven
defaults from the active ScreenOptions are applied once (enabling
mouse, keyboard enhancements, and in-band resize as configured), which
may emit escapes to the terminal.
// Sync loop: read, observe, handle, render.
loop {
let ev = screen.read_event()?;
screen.observe_event(&ev)?; // keep capability tracking alive
// ... handle ev ...
screen.render()?;
}// Async loop: same contract over an EventStream.
use tokio_stream::StreamExt;
let mut events = screen.event_stream();
while let Some(ev) = events.next().await {
let ev = ev?;
screen.observe_event(&ev)?; // keep capability tracking alive
// ... handle ev ...
screen.render()?;
}Source§impl<I, O> Screen<I, O>
impl<I, O> Screen<I, O>
Sourcepub fn new(terminal: Terminal<I, O>) -> Result<Self>
pub fn new(terminal: Terminal<I, O>) -> Result<Self>
Construct a screen over terminal without touching the terminal:
size the renderer to it and create an EventSource on its input
half. The terminal is left as-is; call Self::init to enter raw
mode and begin a session.
Sourcepub fn init(&mut self) -> Result<()>
pub fn init(&mut self) -> Result<()>
Begin a session with the default ScreenOptions. See
Self::init_with.
Sourcepub fn init_with(&mut self, options: ScreenOptions) -> Result<()>
pub fn init_with(&mut self, options: ScreenOptions) -> Result<()>
Begin a session: enter raw mode, apply the always-on defaults from
options, and send the capability queries whose replies the event
loop consumes. Discovery-driven defaults are applied later, once the
terminating Primary DA reply confirms the detected capabilities (see
Self::capabilities). Call once after Self::new, before
rendering.
Sourcepub fn get_window_size(&self) -> Result<Winsize>
pub fn get_window_size(&self) -> Result<Winsize>
Query the current terminal window size (output half first, input as
fallback). This is a live query; the cached
window_cells /
window_pixels accessors return the
last-observed values without I/O.
Sourcepub fn autoresize(&mut self) -> Result<()>
pub fn autoresize(&mut self) -> Result<()>
Re-query the terminal size and resize the managed area to fit: the full
terminal size in fullscreen (alternate screen on), or the terminal
width with the current managed height preserved inline (alternate
screen off). Refreshes the cached window_cells
/ window_pixels; on platforms whose size
query reports no pixel size (e.g. the Windows console) the pixel size
is requested over the wire.
Sourcepub fn finish(self) -> Result<()>
pub fn finish(self) -> Result<()>
Consume the screen and hand the terminal back to the shell: tear down every staged mode, reset the managed area, flush, and restore the terminal’s prior state.
Sourcepub fn pause(&mut self) -> Result<()>
pub fn pause(&mut self) -> Result<()>
Hand the terminal back to the shell without consuming the screen,
e.g. to run a child process. Re-enter with Self::resume. Like
Self::finish but keeps the screen so the session can continue.
Sourcepub fn resume(&mut self) -> Result<()>
pub fn resume(&mut self) -> Result<()>
Re-acquire the terminal after a Self::pause or Self::suspend:
re-enter raw mode, refit the managed area to the current viewport, re-apply
the saved render state and modes, and force a full repaint.
Trait Implementations§
Source§impl<I, O> Bounded for Screen<I, O>
impl<I, O> Bounded for Screen<I, O>
Source§impl<I, O> SurfaceMut for Screen<I, O>
impl<I, O> SurfaceMut for Screen<I, O>
Source§fn set_cell(&mut self, pos: Position, cell: &Cell)
fn set_cell(&mut self, pos: Position, cell: &Cell)
cell at pos. Implementations are responsible for
wide-cell semantics (continuation markers, blanking covered
cells) and any dirty tracking they care to do. Taking &Cell
lets implementations skip the clone when the destination
already matches. Read moreSource§fn insert_lines(&mut self, y: u16, n: u16, bounds_bottom: u16, fill: &Cell)
fn insert_lines(&mut self, y: u16, n: u16, bounds_bottom: u16, fill: &Cell)
n blank rows at y, pushing existing rows down within
[y, bounds_bottom). Rows pushed past bounds_bottom are lost.
Freed top rows are filled with fill. Read moreSource§fn delete_lines(&mut self, y: u16, n: u16, bounds_bottom: u16, fill: &Cell)
fn delete_lines(&mut self, y: u16, n: u16, bounds_bottom: u16, fill: &Cell)
n rows at y, pulling existing rows up within
[y, bounds_bottom). The bottom n rows of the window are
filled with fill. Read moreSource§fn insert_cells(
&mut self,
pos: Position,
n: u16,
bounds_right: u16,
fill: &Cell,
)
fn insert_cells( &mut self, pos: Position, n: u16, bounds_right: u16, fill: &Cell, )
n blank cells at pos, pushing cells in
[pos.x, bounds_right) right within row pos.y. Cells pushed
past bounds_right are lost. The freed slots [pos.x, pos.x + n)
are filled with fill. Read moreSource§fn delete_cells(
&mut self,
pos: Position,
n: u16,
bounds_right: u16,
fill: &Cell,
)
fn delete_cells( &mut self, pos: Position, n: u16, bounds_right: u16, fill: &Cell, )
n cells at pos, pulling cells in
[pos.x + n, bounds_right) left within row pos.y. The freed
slots [bounds_right - n, bounds_right) are filled with fill. Read moreSource§fn clear(&mut self)
fn clear(&mut self)
Cell::BLANK. Read moreSource§fn clear_rect(&mut self, rect: Rect)
fn clear_rect(&mut self, rect: Rect)
Cell::BLANK. Read moreSource§impl<I, O> TextSurface for Screen<I, O>
impl<I, O> TextSurface for Screen<I, O>
Source§fn width_mode(&self) -> WidthMode
fn width_mode(&self) -> WidthMode
Source§fn eaw_wide(&self) -> bool
fn eaw_wide(&self) -> bool
Source§fn set_str(
&mut self,
pos: impl Into<Position>,
s: &str,
style: impl Into<Style>,
) -> Position
fn set_str( &mut self, pos: impl Into<Position>, s: &str, style: impl Into<Style>, ) -> Position
Source§fn set_str_wrap(
&mut self,
pos: impl Into<Position>,
s: &str,
wrap: WrapMode,
style: impl Into<Style>,
) -> Position
fn set_str_wrap( &mut self, pos: impl Into<Position>, s: &str, wrap: WrapMode, style: impl Into<Style>, ) -> Position
Source§fn set_str_rect(
&mut self,
rect: impl Into<Rect>,
s: &str,
style: impl Into<Style>,
) -> Position
fn set_str_rect( &mut self, rect: impl Into<Rect>, s: &str, style: impl Into<Style>, ) -> Position
Source§fn set_str_rect_wrap(
&mut self,
rect: impl Into<Rect>,
s: &str,
wrap: WrapMode,
style: impl Into<Style>,
) -> Position
fn set_str_rect_wrap( &mut self, rect: impl Into<Rect>, s: &str, wrap: WrapMode, style: impl Into<Style>, ) -> Position
Source§fn set_str_truncate(
&mut self,
pos: impl Into<Position>,
s: &str,
tail: &str,
tail_style: impl Into<Style>,
) -> Position
fn set_str_truncate( &mut self, pos: impl Into<Position>, s: &str, tail: &str, tail_style: impl Into<Style>, ) -> Position
Source§fn set_str_rect_truncate(
&mut self,
rect: impl Into<Rect>,
s: &str,
tail: &str,
tail_style: impl Into<Style>,
) -> Position
fn set_str_rect_truncate( &mut self, rect: impl Into<Rect>, s: &str, tail: &str, tail_style: impl Into<Style>, ) -> Position
Source§fn str_width(&self, s: &str) -> u16
fn str_width(&self, s: &str) -> u16
s in terminal columns. Read moreSource§impl<I, O> Write for Screen<I, O>
impl<I, O> Write for Screen<I, O>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Append raw bytes to the staging buffer, ordered with any staged mode
or frame bytes. They reach the terminal on the next flush.
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Auto Trait Implementations§
impl<I, O> Freeze for Screen<I, O>
impl<I, O> RefUnwindSafe for Screen<I, O>where
I: RefUnwindSafe,
O: RefUnwindSafe,
impl<I, O> Send for Screen<I, O>where
O: Send,
impl<I, O> Sync for Screen<I, O>
impl<I, O> Unpin for Screen<I, O>
impl<I, O> UnsafeUnpin for Screen<I, O>where
I: UnsafeUnpin,
O: UnsafeUnpin,
impl<I, O> UnwindSafe for Screen<I, O>where
I: UnwindSafe,
O: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S> Encode for S
impl<S> Encode for S
Source§fn encode<W: Write>(&self, w: &mut W) -> Result<()>
fn encode<W: Write>(&self, w: &mut W) -> Result<()>
w as escape sequences and text. Read more