Expand description
Declarative input collection for CLI applications.
standout-input provides a unified way to acquire user input from multiple
sources—CLI arguments, stdin, environment variables, editors, and interactive
prompts—with automatic fallback chains.
§Quick Start
ⓘ
use standout_input::{InputChain, ArgSource, StdinSource, DefaultSource};
// Try argument first, then piped stdin, then default
let message = InputChain::<String>::new()
.try_source(ArgSource::new("message"))
.try_source(StdinSource::new())
.default("default message".to_string())
.resolve(&matches)?;§Features
editor(default) - Enable [EditorCollector] for editor-based inputsimple-prompts(default) - Enable basic terminal promptsinquire- Enable rich TUI prompts via the inquire crate
§Architecture
The crate is built around the InputCollector trait, which all input
sources implement. Sources are composed into InputChains that try each
source in order until one provides input.
InputChain
├── ArgSource → None (not provided)
├── StdinSource → None (not piped)
├── EditorSource → Some("user input") ← returns this
└── DefaultSource → (not reached)§Testing
All sources accept mock implementations for testing:
use standout_input::{StdinSource, env::MockStdin};
// Test with simulated piped input
let source = StdinSource::with_reader(MockStdin::piped("test input"));Re-exports§
pub use sources::read_if_piped;pub use sources::ArgSource;pub use sources::ClipboardSource;pub use sources::DefaultSource;pub use sources::EnvSource;pub use sources::FlagSource;pub use sources::StdinSource;pub use sources::EditorRunner;pub use sources::EditorSource;pub use sources::MockEditorResult;pub use sources::MockEditorRunner;pub use sources::ConfirmPromptSource;pub use sources::MockTerminal;pub use sources::TerminalIO;pub use sources::TextPromptSource;pub use env::MockClipboard;pub use env::MockEnv;pub use env::MockStdin;pub use env::reset_default_clipboard_reader;pub use env::reset_default_stdin_reader;pub use env::set_default_clipboard_reader;pub use env::set_default_stdin_reader;pub use env::DefaultClipboard;pub use env::DefaultStdin;
Modules§
Structs§
- Input
Chain - Chain multiple input sources with fallback behavior.
- Inputs
- Name-keyed storage for resolved inputs.
- Prompt
Context - Context the source passes to a
PromptResponder. - Resolved
Input - Information about how input was resolved.
- Scripted
Responder - A position-based scripted responder.
Enums§
- Input
Error - Errors that can occur during input collection.
- Input
Source Kind - The kind of source that provided input.
- Missing
Input - Error returned when a named input is missing or stored under a different type.
- Prompt
Kind - The kind of prompt being responded to.
- Prompt
Response - A response a
PromptRespondercan return.
Traits§
- Input
Collector - A source that can collect input of type T.
- Prompt
Responder - Test seam for the
.prompt()shortcut on interactive sources.
Functions§
- reset_
default_ prompt_ responder - Clears the override installed by
set_default_prompt_responder. - set_
default_ prompt_ responder - Installs a process-global
PromptResponderthat every.prompt()call on an interactive source will route through untilreset_default_prompt_responderis called.