Struct dialoguer::FuzzySelect
source · pub struct FuzzySelect<'a> { /* private fields */ }
Expand description
Renders a select prompt with fuzzy search.
User can use fuzzy search to limit selectable items.
Interaction returns index of an item selected in the order they appear in item
invocation or items
slice.
Example
use dialoguer::FuzzySelect;
fn main() {
let items = vec!["foo", "bar", "baz"];
let selection = FuzzySelect::new()
.with_prompt("What do you choose?")
.items(&items)
.interact()
.unwrap();
println!("You chose: {}", items[selection]);
}
Implementations§
source§impl FuzzySelect<'static>
impl FuzzySelect<'static>
source§impl FuzzySelect<'_>
impl FuzzySelect<'_>
sourcepub fn clear(self, val: bool) -> Self
pub fn clear(self, val: bool) -> Self
Sets the clear behavior of the menu.
The default is to clear the menu.
sourcepub fn default(self, val: usize) -> Self
pub fn default(self, val: usize) -> Self
Sets a default for the menu
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let selections = &[
"Ice Cream",
"Vanilla Cupcake",
"Chocolate Muffin",
"A Pile of sweet, sweet mustard",
"Carrots",
"Peas",
"Pistacio",
"Mustard",
"Cream",
"Banana",
"Chocolate",
"Flakes",
"Corn",
"Cake",
"Tarte",
"Cheddar",
"Vanilla",
"Hazelnut",
"Flour",
"Sugar",
"Salt",
"Potato",
"French Fries",
"Pizza",
"Mousse au chocolat",
"Brown sugar",
"Blueberry",
"Burger",
];
let selection = FuzzySelect::with_theme(&ColorfulTheme::default())
.with_prompt("Pick your flavor")
.default(0)
.items(&selections[..])
.interact()
.unwrap();
println!("Enjoy your {}!", selections[selection]);
}
sourcepub fn items<T: ToString>(self, items: &[T]) -> Self
pub fn items<T: ToString>(self, items: &[T]) -> Self
Adds multiple items to the fuzzy selector.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let selections = &[
"Ice Cream",
"Vanilla Cupcake",
"Chocolate Muffin",
"A Pile of sweet, sweet mustard",
"Carrots",
"Peas",
"Pistacio",
"Mustard",
"Cream",
"Banana",
"Chocolate",
"Flakes",
"Corn",
"Cake",
"Tarte",
"Cheddar",
"Vanilla",
"Hazelnut",
"Flour",
"Sugar",
"Salt",
"Potato",
"French Fries",
"Pizza",
"Mousse au chocolat",
"Brown sugar",
"Blueberry",
"Burger",
];
let selection = FuzzySelect::with_theme(&ColorfulTheme::default())
.with_prompt("Pick your flavor")
.default(0)
.items(&selections[..])
.interact()
.unwrap();
println!("Enjoy your {}!", selections[selection]);
}
sourcepub fn with_initial_text<S: Into<String>>(self, initial_text: S) -> Self
pub fn with_initial_text<S: Into<String>>(self, initial_text: S) -> Self
Sets the search text that a fuzzy search starts with.
sourcepub fn with_prompt<S: Into<String>>(self, prompt: S) -> Self
pub fn with_prompt<S: Into<String>>(self, prompt: S) -> Self
Prefaces the menu with a prompt.
When a prompt is set the system also prints out a confirmation after the fuzzy selection.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let selections = &[
"Ice Cream",
"Vanilla Cupcake",
"Chocolate Muffin",
"A Pile of sweet, sweet mustard",
"Carrots",
"Peas",
"Pistacio",
"Mustard",
"Cream",
"Banana",
"Chocolate",
"Flakes",
"Corn",
"Cake",
"Tarte",
"Cheddar",
"Vanilla",
"Hazelnut",
"Flour",
"Sugar",
"Salt",
"Potato",
"French Fries",
"Pizza",
"Mousse au chocolat",
"Brown sugar",
"Blueberry",
"Burger",
];
let selection = FuzzySelect::with_theme(&ColorfulTheme::default())
.with_prompt("Pick your flavor")
.default(0)
.items(&selections[..])
.interact()
.unwrap();
println!("Enjoy your {}!", selections[selection]);
}
sourcepub fn report(self, val: bool) -> Self
pub fn report(self, val: bool) -> Self
Indicates whether to report the selected value after interaction.
The default is to report the selection.
sourcepub fn highlight_matches(self, val: bool) -> Self
pub fn highlight_matches(self, val: bool) -> Self
Indicates whether to highlight matched indices
The default is to highlight the indices
sourcepub fn vim_mode(self, val: bool) -> Self
pub fn vim_mode(self, val: bool) -> Self
Indicated whether to allow the use of vim mode
Vim mode can be entered by pressing Escape. This then allows the user to navigate using hjkl.
The default is to disable vim mode.
sourcepub fn max_length(self, rows: usize) -> Self
pub fn max_length(self, rows: usize) -> Self
Sets the maximum number of visible options.
The default is the height of the terminal minus 2.
sourcepub fn interact(self) -> Result<usize>
pub fn interact(self) -> Result<usize>
Enables user interaction and returns the result.
The user can select the items using ‘Enter’ and the index of selected item will be returned.
The dialog is rendered on stderr.
Result contains index
of selected item if user hit ‘Enter’.
This unlike interact_opt
does not allow to quit with ‘Esc’ or ‘q’.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let selections = &[
"Ice Cream",
"Vanilla Cupcake",
"Chocolate Muffin",
"A Pile of sweet, sweet mustard",
"Carrots",
"Peas",
"Pistacio",
"Mustard",
"Cream",
"Banana",
"Chocolate",
"Flakes",
"Corn",
"Cake",
"Tarte",
"Cheddar",
"Vanilla",
"Hazelnut",
"Flour",
"Sugar",
"Salt",
"Potato",
"French Fries",
"Pizza",
"Mousse au chocolat",
"Brown sugar",
"Blueberry",
"Burger",
];
let selection = FuzzySelect::with_theme(&ColorfulTheme::default())
.with_prompt("Pick your flavor")
.default(0)
.items(&selections[..])
.interact()
.unwrap();
println!("Enjoy your {}!", selections[selection]);
}
sourcepub fn interact_opt(self) -> Result<Option<usize>>
pub fn interact_opt(self) -> Result<Option<usize>>
Enables user interaction and returns the result.
The user can select the items using ‘Enter’ and the index of selected item will be returned.
The dialog is rendered on stderr.
Result contains Some(index)
if user hit ‘Enter’ or None
if user cancelled with ‘Esc’ or ‘q’.
Example
use dialoguer::FuzzySelect;
fn main() {
let items = vec!["foo", "bar", "baz"];
let selection = FuzzySelect::new()
.items(&items)
.interact_opt()
.unwrap();
match selection {
Some(index) => println!("You chose: {}", items[index]),
None => println!("You did not choose anything.")
}
}
sourcepub fn interact_on(self, term: &Term) -> Result<usize>
pub fn interact_on(self, term: &Term) -> Result<usize>
Like interact
but allows a specific terminal to be set.
sourcepub fn interact_on_opt(self, term: &Term) -> Result<Option<usize>>
pub fn interact_on_opt(self, term: &Term) -> Result<Option<usize>>
Like interact_opt
but allows a specific terminal to be set.
source§impl<'a> FuzzySelect<'a>
impl<'a> FuzzySelect<'a>
sourcepub fn with_theme(theme: &'a dyn Theme) -> Self
pub fn with_theme(theme: &'a dyn Theme) -> Self
Creates a fuzzy select prompt with a specific theme.
Example
use dialoguer::{theme::ColorfulTheme, FuzzySelect};
fn main() {
let selection = FuzzySelect::with_theme(&ColorfulTheme::default())
.items(&["foo", "bar", "baz"])
.interact()
.unwrap();
}
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let selections = &[
"Ice Cream",
"Vanilla Cupcake",
"Chocolate Muffin",
"A Pile of sweet, sweet mustard",
"Carrots",
"Peas",
"Pistacio",
"Mustard",
"Cream",
"Banana",
"Chocolate",
"Flakes",
"Corn",
"Cake",
"Tarte",
"Cheddar",
"Vanilla",
"Hazelnut",
"Flour",
"Sugar",
"Salt",
"Potato",
"French Fries",
"Pizza",
"Mousse au chocolat",
"Brown sugar",
"Blueberry",
"Burger",
];
let selection = FuzzySelect::with_theme(&ColorfulTheme::default())
.with_prompt("Pick your flavor")
.default(0)
.items(&selections[..])
.interact()
.unwrap();
println!("Enjoy your {}!", selections[selection]);
}
Trait Implementations§
source§impl<'a> Clone for FuzzySelect<'a>
impl<'a> Clone for FuzzySelect<'a>
source§fn clone(&self) -> FuzzySelect<'a>
fn clone(&self) -> FuzzySelect<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more