Skip to main content

pick_a_path/
pick_a_path.rs

1use cloud_terrastodon_user_input::Choice;
2use cloud_terrastodon_user_input::PickerTui;
3
4pub fn main() -> eyre::Result<()> {
5    let mut choices = Vec::new();
6    let dir = std::fs::read_dir(".")?;
7    for entry in dir {
8        let entry = entry?;
9        choices.push(entry);
10    }
11
12    let chosen = PickerTui::new()
13        .set_header("Pick a path")
14        .pick_one(choices.into_iter().map(|entry| Choice {
15            key: entry.path().display().to_string(), // the value shown to the user
16            value: entry, // the inner value we want to have after the user picks
17        }))?;
18
19    println!("You chose {}", chosen.file_name().to_string_lossy());
20
21    Ok(())
22}