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>

source

pub fn new() -> Self

Creates a multi select prompt with default theme.

source§

impl MultiSelect<'_>

source

pub fn clear(self, val: bool) -> Self

Sets the clear behavior of the menu.

The default is to clear the menu.

source

pub fn defaults(self, val: &[bool]) -> Self

Sets a defaults for the menu.

source

pub fn max_length(self, val: usize) -> Self

Sets an optional max length for a page

Max length is disabled by None

source

pub fn item<T: ToString>(self, item: T) -> Self

Add a single item to the selector.

source

pub fn item_checked<T: ToString>(self, item: T, checked: bool) -> Self

Add a single item to the selector with a default checked state.

source

pub fn items<T: ToString>(self, items: &[T]) -> Self

Adds multiple items to the selector.

source

pub fn items_checked<T: ToString>(self, items: &[(T, bool)]) -> Self

Adds multiple items to the selector with checked state

source

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.

source

pub fn report(self, val: bool) -> Self

Indicates whether to report the selected values after interaction.

The default is to report the selections.

source

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’.

source

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.")
    }
}
source

pub fn interact_on(self, term: &Term) -> Result<Vec<usize>>

Like interact but allows a specific terminal to be set.

source

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>

source

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>

source§

fn clone(&self) -> MultiSelect<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for MultiSelect<'static>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto 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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.