Expand description
Interactive prompts for guided CLI flows.
A cohesive input layer beside crate::render and crate::theme: it asks
a question plus a fixed set of Choices and returns a typed answer, reusing
the resolved Palette and Glyphs
so styling honours NO_COLOR, TTY, and UTF-8 detection exactly like the rest
of the CLI layer.
Prompts speak through a Terminal seam rather than raw stdio, so the same
question renders as a numbered list over a pipe, as a live arrow-key widget on
a TTY, or as a scripted sequence in a test — without the calling code changing.
§Modules
choice—Choiceand its stableChoiceId.mode—PromptModeinteractive/non-interactive resolution.key— theKeykeystroke vocabulary for key-driven terminals.validate— theValidatortrait for re-asking on invalid input.terminal— theTerminalseam: line, rich (raw-mode), and scripted media.render— shared choice/frame rendering used by every terminal.kinds— one behavioural module per question type.prompter— thePrompterdriver and its question methods.
§Interaction models
One set of prompt-kind logic drives three realities, chosen automatically:
- a line terminal (cooked stdio) prints a numbered list and reads a typed answer — always available, dependency-free, and pipe-friendly;
- a rich terminal (raw mode, behind the
interactivefeature) reads arrow keys and space to drive live radio and checkbox lists; - a scripted terminal replays canned keys or lines for deterministic tests.
Prompter::from_env selects rich when a TTY is present and the feature is
compiled, else line; tests bind a
ScriptedTerminal directly.
§Non-interactive fallback
The driver resolves its behaviour once, up front, from a PromptMode:
PromptMode::Interactive— render prompts and read answers.PromptMode::NonInteractive— never block: each question resolves to its declared default (therecommendedChoicefor a selection, the supplied default for a confirm/text). A required question with no default is a typedAppErrorrather than an invented answer or a hang.
Re-exports§
pub use choice::Choice;pub use choice::ChoiceId;pub use key::Key;pub use mode::PromptMode;pub use prompter::Prompter;pub use terminal::Capabilities;pub use terminal::LineTerminal;pub use terminal::ScriptedTerminal;pub use terminal::Terminal;pub use validate::Validation;pub use validate::Validator;pub use validate::non_empty;pub use terminal::RichTerminal;
Modules§
- choice
- Selectable options:
Choiceand its stableChoiceId. - key
- The keystroke vocabulary a key-driven
Terminalyields. - kinds
- The prompt kinds: one behavioural module per question type.
- mode
- How a
Promptersources answers. - prompter
- The
Prompter: a terminal-agnostic driver for every prompt kind. - render
- Shared choice/frame rendering for both line-driven and key-driven prompts.
- terminal
- The interactive medium a
Prompterspeaks through. - validate
- Answer validation with interactive re-ask.