pub fn pick_file<C>(cmd: C, path: PathBuf) -> Result<PathBuf>Expand description
Asks the user to select a file from the filesystem, starting at directory path.
Requires a function that produces the command as cmd, because commands aren’t cloneable.
Examples found in repository?
examples/demo.rs (line 17)
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}