Expand description
Program — the interactive terminal session.
Program<I, O> is what you build a terminal application on. It owns the
things a session needs and a Screen to render with:
- a
Terminalfor the raw-mode lifecycle, - an
EventSourcefor decoded input, - the terminal and input modes (mouse, bracketed paste, focus reporting, in-band resize, titles, colors, cursor style, keyboard enhancements), tracked so they can be torn down on a shell handoff and re-applied after,
- the
Capabilitiesthe terminal has reported, recorded from replies as they pass through the read path.
Drawing is not on Program. Reach the renderer with
screen_mut and call
render on it — that is the only render in the crate,
and the only flush.
Construction is inert: Program::new (and the stdio
/ open shortcuts) only build the program. Begin a
session with Program::init, which enters raw mode. Nothing is probed
unless you ask: call Program::query_capabilities for that. Teardown is
explicit: there is no Drop.
Hand the terminal back to the shell with Program::finish (consume),
Program::pause (keep, e.g. to shell out), or Program::suspend
(pause, then stop the process with SIGTSTP); resume a
paused/suspended program with Program::resume.
use uncurses::program::Program;
use uncurses::style::Style;
use uncurses::text::TextSurface;
let mut program = Program::open()?; // build over /dev/tty
program.init()?; // raw mode; probes nothing on its own
program.enter_alt_screen()?;
let screen = program.screen_mut();
screen.set_str((0, 0), "hello", Style::default());
screen.render()?;
let event = program.read_event()?; // reply tracking is automatic
program.finish()?; // restore the terminal§Options and defaults
init uses ProgramOptions::default;
init_with takes an explicit ProgramOptions to
choose whether to enable bracketed paste and mouse tracking at startup.
Those take effect immediately at init.
The three prefer_* fields are discovery-driven instead: they enable
grapheme-cluster mode, in-band resize, and synchronized output only once
the terminal reports the mode as available. Since a program never probes
on its own, that means calling
query_capabilities and
reading the replies (see capabilities).
Structs§
- Capabilities
- What the terminal told us about itself.
- Mouse
Tracking - Optional mouse tracking features layered on top of basic button tracking.
- Program
- An interactive terminal session composing a
Terminal, anEventSource, and aScreento render with. See the module documentation for the lifecycle. - Program
Options - Defaults applied by
Program::init_with.
Enums§
- Cursor
Shape - The visual shape of the text cursor, independent of whether it blinks.
- Progress
State - A progress indication reported to the terminal with
OSC 9;4, shown in the taskbar, tab, or window chrome by terminals that support it.