1use dialoguer_ext::{theme::ColorfulTheme, Select};
2
3fn main() {
4 let selections = &[
5 "Ice Cream",
6 "Vanilla Cupcake",
7 "Chocolate Muffin",
8 "A Pile of sweet, sweet mustard",
9 ];
10
11 let selection = Select::with_theme(&ColorfulTheme::default())
12 .with_prompt("Pick your flavor")
13 .default(0)
14 .items(&selections[..])
15 .interact()
16 .unwrap();
17
18 println!("Enjoy your {}!", selections[selection]);
19
20 let selection = Select::with_theme(&ColorfulTheme::default())
21 .with_prompt("Optionally pick your flavor")
22 .default(0)
23 .items(&selections[..])
24 .interact_opt()
25 .unwrap();
26
27 if let Some(selection) = selection {
28 println!("Enjoy your {}!", selections[selection]);
29 } else {
30 println!("You didn't select anything!");
31 }
32
33 let selection = Select::with_theme(&ColorfulTheme::default())
34 .with_prompt("Pick your flavor, hint it might be on the second page")
35 .default(0)
36 .max_length(2)
37 .items(&selections[..])
38 .interact()
39 .unwrap();
40
41 println!("Enjoy your {}!", selections[selection]);
42
43 let keys = vec![console::Key::Char('q'),console::Key::Char('s')];
44
45 let selection_with_keys = Select::with_theme(&ColorfulTheme::default())
46 .with_prompt("Pick your flavor (press q or s to skip)")
47 .default(0)
48 .items(&selections[..])
49 .interact_opt_with_keys(&keys)
50 .unwrap();
51
52 if let Some(index) = selection_with_keys.index {
53 println!("Enjoy your {}!", selections[index]);
54 }
55 if let Some(key) = selection_with_keys.key {
56 println!("You skippng by pressing {:?}!", key);
57 }
58
59
60
61}