Struct dialoguer::FuzzySelect
source · [−]pub struct FuzzySelect<'a> { /* private fields */ }
Expand description
Renders a selection menu that user can fuzzy match to reduce set.
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.
Examples
use dialoguer::{
FuzzySelect,
theme::ColorfulTheme
};
use console::Term;
fn main() -> std::io::Result<()> {
let items = vec!["Item 1", "item 2"];
let selection = FuzzySelect::with_theme(&ColorfulTheme::default())
.items(&items)
.default(0)
.interact_on_opt(&Term::stderr())?;
match selection {
Some(index) => println!("User selected item : {}", items[index]),
None => println!("User did not select anything")
}
Ok(())
}
Implementations
sourceimpl FuzzySelect<'static>
impl FuzzySelect<'static>
sourceimpl FuzzySelect<'_>
impl FuzzySelect<'_>
sourcepub fn clear(&mut self, val: bool) -> &mut Self
pub fn clear(&mut self, val: bool) -> &mut Self
Sets the clear behavior of the menu.
The default is to clear the menu.
sourcepub fn item<T: ToString>(&mut self, item: T) -> &mut Self
pub fn item<T: ToString>(&mut self, item: T) -> &mut Self
Add a single item to the fuzzy selector.
sourcepub fn items<T: ToString>(&mut self, items: &[T]) -> &mut Self
pub fn items<T: ToString>(&mut self, items: &[T]) -> &mut Self
Adds multiple items to the fuzzy selector.
sourcepub fn with_prompt<S: Into<String>>(&mut self, prompt: S) -> &mut Self
pub fn with_prompt<S: Into<String>>(&mut self, prompt: S) -> &mut Self
Prefaces the menu with a prompt.
When a prompt is set the system also prints out a confirmation after the fuzzy selection.
sourcepub fn report(&mut self, val: bool) -> &mut Self
pub fn report(&mut self, val: bool) -> &mut Self
Indicates whether to report the selected value after interaction.
The default is to report the selection.
sourcepub fn highlight_matches(&mut self, val: bool) -> &mut Self
pub fn highlight_matches(&mut self, val: bool) -> &mut Self
Indicates whether to highlight matched indices
The default is to highlight the indices
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’.
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’.
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.
sourceimpl<'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
Same as new
but with a specific theme.
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for FuzzySelect<'a>
impl<'a> !Send for FuzzySelect<'a>
impl<'a> !Sync for FuzzySelect<'a>
impl<'a> Unpin for FuzzySelect<'a>
impl<'a> !UnwindSafe for FuzzySelect<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more