2 releases
| 0.9.1 | Sep 16, 2025 |
|---|---|
| 0.9.0 | Sep 16, 2025 |
#496 in Value formatting
2,966 downloads per month
7KB
86 lines
inquire-derive
Derive macros for the inquire crate.
Usage
Put these lines in your Cargo.toml, under [dependencies].
inquire = "0.9.1"
inquire-derive = "0.9.1"
Then use the Selectable derive macro on your enums:
use inquire_derive::Selectable;
use std::fmt::{Display, Formatter};
#[derive(Debug, Copy, Clone, Selectable)]
enum Color {
Red,
Green,
Blue,
}
impl Display for Color {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
// Now you can use:
let color = Color::select("Choose a color:").prompt()?;
let colors = Color::multi_select("Choose colors:").prompt()?;
Features
The Selectable derive macro generates two methods for your enum:
select(msg: &str)- Returns aSelectbuilder for single selectionmulti_select(msg: &str)- Returns aMultiSelectbuilder for multiple selection
Both methods return builders that can be customized before calling .prompt():
let color = Color::select("Choose a color:")
.with_help_message("Use arrow keys to navigate")
.with_page_size(5)
.prompt()?;
let colors = Color::multi_select("Choose colors:")
.with_default(&[0, 1]) // Pre-select first two options
.with_help_message("Space to select, Enter to confirm")
.prompt()?;
Examples
Run the examples to see the derive macro in action:
cargo run --example enum_select_derive
cargo run --example enum_comprehensive
Requirements
Your enum must implement:
Display- for showing options to the userDebug- required by inquireCopyandClone- for efficient handling- Be
'static- for the generated code
Dependencies
~170–590KB
~14K SLoC