2 releases

0.9.1 Sep 16, 2025
0.9.0 Sep 16, 2025

#496 in Value formatting

Download history 151/week @ 2025-09-10 116/week @ 2025-09-17 15/week @ 2025-09-24 49/week @ 2025-10-01 36/week @ 2025-10-08 26/week @ 2025-10-15 27/week @ 2025-10-22 654/week @ 2025-10-29 698/week @ 2025-11-05 872/week @ 2025-11-12 962/week @ 2025-11-19 519/week @ 2025-11-26 831/week @ 2025-12-03 491/week @ 2025-12-10

2,966 downloads per month

MIT license

7KB
86 lines

Latest Version Build status Supported platforms License


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 a Select builder for single selection
  • multi_select(msg: &str) - Returns a MultiSelect builder 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 user
  • Debug - required by inquire
  • Copy and Clone - for efficient handling
  • Be 'static - for the generated code

Dependencies

~170–590KB
~14K SLoC