Struct dialoguer::MultiSelect
source · pub struct MultiSelect<'a> { /* private fields */ }
Expand description
Renders a multi select prompt.
§Example
use dialoguer::MultiSelect;
fn main() {
let items = vec!["foo", "bar", "baz"];
let selection = MultiSelect::new()
.with_prompt("What do you choose?")
.items(&items)
.interact()
.unwrap();
println!("You chose:");
for i in selection {
println!("{}", items[i]);
}
}
Implementations§
source§impl MultiSelect<'static>
impl MultiSelect<'static>
source§impl MultiSelect<'_>
impl MultiSelect<'_>
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 max_length(self, val: usize) -> Self
pub fn max_length(self, val: usize) -> Self
Sets an optional max length for a page
Max length is disabled by None
sourcepub fn item_checked<T: ToString>(self, item: T, checked: bool) -> Self
pub fn item_checked<T: ToString>(self, item: T, checked: bool) -> Self
Add a single item to the selector with a default checked state.
sourcepub fn items_checked<T: ToString>(self, items: &[(T, bool)]) -> Self
pub fn items_checked<T: ToString>(self, items: &[(T, bool)]) -> Self
Adds multiple items to the selector with checked state
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.
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(self, val: bool) -> Self
pub fn report(self, val: bool) -> 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’.
§Example
use dialoguer::MultiSelect;
fn main() {
let items = vec!["foo", "bar", "baz"];
let ordered = MultiSelect::new()
.items(&items)
.interact_opt()
.unwrap();
match ordered {
Some(positions) => {
println!("You chose:");
for i in positions {
println!("{}", items[i]);
}
},
None => println!("You did not choose anything.")
}
}
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.
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.
source§impl<'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.
§Example
use dialoguer::{theme::ColorfulTheme, MultiSelect};
fn main() {
let selection = MultiSelect::with_theme(&ColorfulTheme::default())
.items(&["foo", "bar", "baz"])
.interact()
.unwrap();
}
Trait Implementations§
source§impl<'a> Clone for MultiSelect<'a>
impl<'a> Clone for MultiSelect<'a>
source§fn clone(&self) -> MultiSelect<'a>
fn clone(&self) -> MultiSelect<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<'a> Freeze for MultiSelect<'a>
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)