Skip to content

Commit

Permalink
Add basic working example of multicount.
Browse files Browse the repository at this point in the history
  • Loading branch information
wegreenall committed Mar 18, 2024
1 parent 7c0ed55 commit a42029d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions inquire/examples/multicount.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use inquire::{
formatter::MultiCountFormatter, list_option::ListOption, validator::Validation, MultiCount,
};

fn main() {
let options = vec![
"Banana",
"Apple",
"Strawberry",
"Grapes",
"Lemon",
"Tangerine",
"Watermelon",
"Orange",
"Pear",
"Avocado",
"Pineapple",
];

let formatter: MultiCountFormatter<'_, &str> = &|a| format!("{} different fruits", a.len());

let ans = MultiCount::new("Select the fruits for your shopping list:", options)
.with_formatter(formatter)
.prompt();

match ans {
Ok(_) => println!("I'll get right on it"),
Err(_) => println!("The shopping list could not be processed"),
}
}

0 comments on commit a42029d

Please sign in to comment.