rusty_cli/inputs/
select_input.rs1use dialoguer::console::Term;
2use dialoguer::theme::ColorfulTheme;
3use dialoguer::Select;
4use std::io::Result;
5
6pub struct SelectInput {}
7
8impl SelectInput {
9
10 pub fn get_value(items: Vec<String>) -> String {
12 items.get(SelectInput::get_selection(items.clone())
13 .unwrap()
14 .unwrap())
15 .unwrap()
16 .to_string()
17 }
18
19 pub fn get_index(items: Vec<String>) -> Option<usize> {
21 SelectInput::get_selection(items).unwrap()
22 }
23
24 fn get_selection(items: Vec<String>) -> Result<Option<usize>> {
26 Select::with_theme(&ColorfulTheme::default())
27 .items(&items)
28 .default(0)
29 .interact_on_opt(&Term::stderr())
30 }
31}
32