Struct dialoguer::MultiSelect
source · [−]pub struct MultiSelect<'a> { /* private fields */ }
Expand description
Renders a multi select prompt.
Example usage
use dialoguer::MultiSelect;
let items = vec!["Option 1", "Option 2"];
let chosen : Vec<usize> = MultiSelect::new()
.items(&items)
.interact()?;
Implementations
sourceimpl MultiSelect<'static>
impl MultiSelect<'static>
sourceimpl MultiSelect<'_>
impl MultiSelect<'_>
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 max_length(&mut self, val: usize) -> &mut Self
pub fn max_length(&mut self, val: usize) -> &mut Self
Sets an optional max length for a page
Max length is disabled by None
sourcepub fn item_checked<T: ToString>(&mut self, item: T, checked: bool) -> &mut Self
pub fn item_checked<T: ToString>(&mut self, item: T, checked: bool) -> &mut Self
Add a single item to the selector with a default checked state.
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 selector.
sourcepub fn items_checked<T: ToString>(&mut self, items: &[(T, bool)]) -> &mut Self
pub fn items_checked<T: ToString>(&mut self, items: &[(T, bool)]) -> &mut Self
Adds multiple items to the selector with checked state
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.
By default, when a prompt is set the system also prints out a confirmation after
the selection. You can opt-out of this with report
.
sourcepub fn report(&mut self, val: bool) -> &mut Self
pub fn report(&mut self, val: bool) -> &mut Self
Indicates whether to report the selected values after interaction.
The default is to report the selections.
sourcepub fn interact(&self) -> Result<Vec<usize>>
pub fn interact(&self) -> Result<Vec<usize>>
Enables user interaction and returns the result.
The user can select the items with the ‘Space’ bar and on ‘Enter’ the indices of selected items will be returned.
The dialog is rendered on stderr.
Result contains Vec<index>
if user hit ‘Enter’.
This unlike interact_opt
does not allow to quit with ‘Esc’ or ‘q’.
sourcepub fn interact_opt(&self) -> Result<Option<Vec<usize>>>
pub fn interact_opt(&self) -> Result<Option<Vec<usize>>>
Enables user interaction and returns the result.
The user can select the items with the ‘Space’ bar and on ‘Enter’ the indices of selected items will be returned.
The dialog is rendered on stderr.
Result contains Some(Vec<index>)
if user hit ‘Enter’ or None
if user cancelled with ‘Esc’ or ‘q’.
sourcepub fn interact_on(&self, term: &Term) -> Result<Vec<usize>>
pub fn interact_on(&self, term: &Term) -> Result<Vec<usize>>
Like interact but allows a specific terminal to be set.
Examples
use dialoguer::MultiSelect;
use console::Term;
fn main() -> std::io::Result<()> {
let selections = MultiSelect::new()
.item("Option A")
.item("Option B")
.interact_on(&Term::stderr())?;
println!("User selected options at indices {:?}", selections);
Ok(())
}
sourcepub fn interact_on_opt(&self, term: &Term) -> Result<Option<Vec<usize>>>
pub fn interact_on_opt(&self, term: &Term) -> Result<Option<Vec<usize>>>
Like interact_opt
but allows a specific terminal to be set.
Examples
use dialoguer::MultiSelect;
use console::Term;
fn main() -> std::io::Result<()> {
let selections = MultiSelect::new()
.item("Option A")
.item("Option B")
.interact_on_opt(&Term::stdout())?;
match selections {
Some(positions) => println!("User selected options at indices {:?}", positions),
None => println!("User exited using Esc or q")
}
Ok(())
}
sourceimpl<'a> MultiSelect<'a>
impl<'a> MultiSelect<'a>
sourcepub fn with_theme(theme: &'a dyn Theme) -> Self
pub fn with_theme(theme: &'a dyn Theme) -> Self
Creates a multi select prompt with a specific theme.
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for MultiSelect<'a>
impl<'a> !Send for MultiSelect<'a>
impl<'a> !Sync for MultiSelect<'a>
impl<'a> Unpin for MultiSelect<'a>
impl<'a> !UnwindSafe for MultiSelect<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more