pick_from_list

Function pick_from_list 

Source
pub fn pick_from_list<T: AsRef<str>>(
    cmd: Option<&mut Command>,
    items: &[T],
    prompt: &str,
) -> Result<String>
Expand description

Asks the user to select an item from a list.

If cmd is Some, an external menu program will be used.
Otherwise, a built-in simple number-based command-line menu (on /dev/tty) will be used, with a prompt.

Note: an external program might return something that’s not in the list!

Examples found in repository?
examples/demo.rs (line 14)
6fn main() {
7    println!("Interactor demo. Type something:");
8
9    let read_result = read_from_tty(|buf, b, tty| {
10        tty.write(&format!("({:?} | {})\n", buf, b).into_bytes());
11    }, false, false).unwrap();
12    println!("Read: {}", String::from_utf8(read_result).unwrap());
13
14    let chosen_ext = pick_from_list(default_menu_cmd().as_mut(), &["first", "second"], "").unwrap();
15    println!("Congratulations, you chose '{}'!!", chosen_ext);
16
17    let chosen_file = pick_file(|| default_menu_cmd(), std::env::current_dir().unwrap()).unwrap();
18    println!("Congratulations, you chose '{}'!!", chosen_file.display());
19
20    let chosen_int = pick_from_list(None, &["first", "second"], "Selection: ").unwrap();
21    println!("Congratulations, you chose '{}'!!", chosen_int);
22}