Expand description
Screen — a self-managing terminal application facade.
Screen<I, O> bundles the three primitives a full-screen terminal
program needs into one owned handle:
- a
Terminalfor the raw-mode lifecycle, - a cell-diff renderer, and
- an
EventSourcefor decoded input (read synchronously).
It additionally owns the non-render terminal/input modes (mouse, bracketed paste, focus reporting, in-band resize, the default foreground/background/cursor colors, the window title, the cursor style, and color-scheme update reports) and tracks them so they can be torn down on a shell handoff and re-applied afterwards.
Construction is inert: Screen::new (and the stdio
/ open shortcuts) only build the screen. Begin a
session with Screen::init, which enters raw mode and sends the
capability queries. Teardown is explicit: there is no Drop.
Hand the terminal back to the shell with Screen::finish (consume),
Screen::pause (keep, e.g. to shell out), or Screen::suspend
(pause, then stop the process with SIGTSTP); resume a
paused/suspended screen with Screen::resume.
use uncurses::screen::Screen;
use uncurses::style::Style;
use uncurses::text::TextSurface;
let mut screen = Screen::open()?; // build over /dev/tty
screen.init()?; // raw mode + capability queries
screen.enter_alt_screen()?;
screen.set_str((0, 0), "hello", Style::default());
screen.render()?;
let event = screen.read_event()?;
screen.observe_event(&event)?; // keep capability tracking alive
screen.finish()?; // restore the terminal§Inline and fullscreen
With the alternate screen on (after enter_alt_screen)
the managed area is the whole terminal viewport, addressed with absolute
moves. Without it (the default) the screen is inline: it occupies the
full terminal width but only as many rows as you draw, anchored in the
normal buffer so scrollback above and the returning shell prompt below
stay intact. Set the inline height with resize, and
push lines into the scrollback above the surface with
insert_above. Call
autoresize to refit to the current window.
Inline (default): the surface lives in the normal buffer, only as
many rows as you draw; scrollback and the shell prompt stay intact.
$ earlier shell output
$ ... scrollback ...
┌─────────────────────────┐
│ managed surface │ <- only the rows you draw, full width
└─────────────────────────┘
$ shell prompt resumes
Fullscreen (after enter_alt_screen): the whole viewport is the
surface, addressed with absolute moves, and restored on exit.
┌─────────────────────────────┐
│ │
│ the whole terminal │
│ viewport is the surface │
│ │
└─────────────────────────────┘§Options and defaults
init uses ScreenOptions::default;
init_with takes an explicit ScreenOptions to
choose the desired keyboard enhancements, whether to enable mouse
tracking at startup, and the in-band-resize and pixel-size behaviors.
Always-on defaults (such as bracketed paste) take effect immediately;
discovery-driven defaults are applied once the terminal answers the
capability queries (see capabilities).
Structs§
- Capabilities
- Terminal capabilities detected from the replies to the queries
Screen::initfires. Every field answers a single question: does the terminal support this? The facade intercepts the reply events as they flow throughread_event/try_read_event, records support here, and applies the render-affecting ones — the app never sees the reply events. Read back withScreen::capabilities. - Mouse
Tracking - Optional mouse tracking features layered on top of basic button tracking.
- Optimizations
- Cell-diff capability flags controlling which optimized escape
sequences the screen’s renderer may emit. Re-exported from the
renderer so applications can configure rendering with
Screen::set_optimizationswithout depending on renderer internals. Terminal capabilities the renderer may use for shorter output. - Screen
- A self-managing terminal application facade composing a
Terminal, a cell-diff renderer, and anEventSourcewith the non-render terminal and input modes. See the module documentation for the lifecycle. - Screen
Options - Desired default behaviors applied by
Screen::init_with.
Enums§
- Cursor
Shape - The visual shape of the text cursor, independent of whether it blinks.