pub fn pick<T>(args: impl Into<FzfArgs<T>>) -> Result<T>Expand description
Prompt the user to pick from a predetermined list of options.
Examples found in repository?
More examples
examples/starting_search.rs (lines 6-11)
4pub fn main() -> eyre::Result<()> {
5 let nouns = vec!["dog", "cat", "house", "pickle", "mouse"];
6 let chosen = pick(FzfArgs {
7 choices: nouns,
8 header: Some("Pick a noun".to_string()),
9 query: Some("ouse".to_string()),
10 ..Default::default()
11 })?;
12 println!("You chose {}", chosen);
13
14 Ok(())
15}examples/pick_a_path.rs (lines 13-23)
5pub fn main() -> eyre::Result<()> {
6 let mut choices = Vec::new();
7 let mut dir = std::fs::read_dir(".")?;
8 while let Some(entry) = dir.next() {
9 let entry = entry?;
10 choices.push(entry);
11 }
12
13 let chosen = pick(FzfArgs {
14 choices: choices
15 .into_iter()
16 .map(|entry| Choice {
17 key: entry.path().display().to_string(), // the value shown to the user
18 value: entry, // the inner value we want to have after the user picks
19 })
20 .collect(),
21 header: Some("Pick a path".to_string()),
22 ..Default::default()
23 })?;
24
25 println!("You chose {}", chosen.file_name().to_string_lossy());
26
27 Ok(())
28}