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 inline origin that maps mouse coordinates into the managed area.
Reads hand each event to you without changes. Replies to terminal
queries are ordinary events: your read loop matches them to its requests.
Capability discovery belongs to the application:
Probe::query_capabilities returns a Capabilities record that your read loop
fills, and Program::apply_defaults acts on it using ProgramOptions.
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 Probe::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 Unix 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()?; // handle input and replies in your loop
program.finish()?; // restore the terminal§Options and defaults
new, stdio, and open
store ProgramOptions::default. Use with_options
to select bracketed paste, mouse tracking, and the initial color profile.
init applies those startup settings.
A Probe selects explicit capability queries. Create it from
Program::env, write through Program::screen_mut, then flush.
Record replies with Capabilities::record and detect the final
Event::PrimaryDeviceAttributes in your input loop.
ProgramOptions selects which supported defaults to adopt.
Pass the record to apply_defaults.
Re-exports§
pub use crate::ansi::program_resume::ProgramResume;pub use crate::ansi::program_status::ProgramStatus;pub use crate::ansi::program_status::ProgramStatusKind;pub use crate::ansi::program_status::ProgramStatusState;
Structs§
- Capabilities
- What the terminal told us about itself.
- Mouse
Tracking - Optional mouse tracking features layered on top of basic button tracking.
- Probe
- Select the terminal queries to write.
- Program
- An interactive terminal session composing a
Terminal, anEventSource, and aScreento render with. See the module documentation for the lifecycle. - Program
Options - Options for session setup.
- State
- Session choices tracked by
Programfor save and restore.
Enums§
- 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.