pub struct MultiSelect<M: Display, T: Clone, O: Display + Clone> { /* private fields */ }
Expand description

MultiSelect struct

Implementations§

source§

impl<M: Display, T: Clone, O: Display + Clone> MultiSelect<M, T, O>

source

pub fn new(message: M) -> Self

Creates a new MultiSelect struct.

Has a shorthand version in multi_select()

Examples
use may_clack::{multi_select, multi_select::MultiSelect};

// these two are equivalent
let mut question = MultiSelect::new("message");
question.option("value", "hint");

let mut question = multi_select("message");
question.option("value", "hint");
source

pub fn option(&mut self, val: T, label: O) -> &mut Self

Add an option without a hint.

Examples
use may_clack::multi_select;

let answer = multi_select("message")
    .option("val1", "label 1")
    .option("val2", "label 2")
    .interact();
println!("answer {:?}", answer);
Examples found in repository?
examples/generic_select.rs (line 39)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() -> Result<(), ClackError> {
	println!();
	intro!(style(" generic select ").reverse());

	let select_string = select("select string")
		.option("val1", SelectEnum::One)
		.option("val2", SelectEnum::One)
		.option("val3", SelectEnum::One)
		.interact()?;

	let select_enum = select("select enum")
		.option(SelectEnum::One, SelectEnum::One)
		.option(SelectEnum::Two, SelectEnum::Two)
		.option(SelectEnum::Three, SelectEnum::Three)
		.interact()?;

	let multi_enum = multi_select("multi_select enum")
		.option(SelectEnum::One, "one")
		.option(SelectEnum::Two, "two")
		.option(SelectEnum::Three, "three")
		.interact()?;

	outro!();

	println!("select string, label enum {:?}", select_string);
	println!("select enum, label enum {:?}", select_enum);
	println!("multi select enum, label string {:?}", multi_enum);

	Ok(())
}
More examples
Hide additional examples
examples/full.rs (line 23)
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
fn main() -> Result<(), ClackError> {
	println!();
	intro!(style(" full ").reverse());

	info!("visit the documentation at https://docs.rs/may-clack");

	let do_input = input("input")
		.default_value("default")
		.cancel(do_cancel)
		.interact()?;
	let do_multi_input = multi_input("multi input")
		.max(4)
		.cancel(do_cancel)
		.interact()?;
	let do_confirm = confirm("confirm").prompts("true", "false").interact()?;
	let do_multi_select = multi_select("multi select")
		.option("opt1", "option 1")
		.option("opt2", "option 2")
		.option_hint("opt3", "option 3", "hint")
		.interact()?;
	let do_select = select("select")
		.option("val1", "value 1")
		.option("val2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.interact()?;

	outro!();

	println!("input {:?}", do_input);
	println!("confirm {:?}", do_confirm);
	println!("multi_input {:?}", do_multi_input);
	println!("multi_select {:?}", do_multi_select);
	println!("select {:?}", do_select);

	Ok(())
}
examples/less.rs (line 22)
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
44
45
46
47
48
49
50
51
52
53
54
fn main() -> Result<(), ClackError> {
	println!();
	intro!(style(" less ").reverse());

	let select_less = select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.option("val 4", "value 4")
		.option("val 5", "value 5")
		.less(3)
		.interact();

	let multi_less_noop = multi_select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.less(5)
		.interact();

	let multi_less = multi_select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.option("val 4", "value 4")
		.option("val 5", "value 5")
		.less(3)
		.interact();

	let mut page_up_down = select("page up / down");
	page_up_down.less(10);

	for i in 0..100 {
		page_up_down.option(i, i);
	}

	let page_up_down = page_up_down.interact()?;

	outro!();

	println!("page_up_down {:?}", page_up_down);
	println!("select_less {:?}", select_less);
	println!("multi_less_noop {:?}", multi_less_noop);
	println!("multi_less {:?}", multi_less);

	Ok(())
}
source

pub fn option_hint<S: Into<String>>( &mut self, val: T, label: O, hint: S ) -> &mut Self

Add an option with a hint.

Examples
use may_clack::multi_select;

let answer = multi_select("message")
    .option("val1", "label 1")
    .option_hint("val2", "label 2", "hint")
    .option("val3", "label 3")
    .interact();
println!("answer {:?}", answer);
Examples found in repository?
examples/full.rs (line 25)
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
fn main() -> Result<(), ClackError> {
	println!();
	intro!(style(" full ").reverse());

	info!("visit the documentation at https://docs.rs/may-clack");

	let do_input = input("input")
		.default_value("default")
		.cancel(do_cancel)
		.interact()?;
	let do_multi_input = multi_input("multi input")
		.max(4)
		.cancel(do_cancel)
		.interact()?;
	let do_confirm = confirm("confirm").prompts("true", "false").interact()?;
	let do_multi_select = multi_select("multi select")
		.option("opt1", "option 1")
		.option("opt2", "option 2")
		.option_hint("opt3", "option 3", "hint")
		.interact()?;
	let do_select = select("select")
		.option("val1", "value 1")
		.option("val2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.interact()?;

	outro!();

	println!("input {:?}", do_input);
	println!("confirm {:?}", do_confirm);
	println!("multi_input {:?}", do_multi_input);
	println!("multi_select {:?}", do_multi_select);
	println!("select {:?}", do_select);

	Ok(())
}
More examples
Hide additional examples
examples/less.rs (line 24)
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
44
45
46
47
48
49
50
51
52
53
54
fn main() -> Result<(), ClackError> {
	println!();
	intro!(style(" less ").reverse());

	let select_less = select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.option("val 4", "value 4")
		.option("val 5", "value 5")
		.less(3)
		.interact();

	let multi_less_noop = multi_select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.less(5)
		.interact();

	let multi_less = multi_select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.option("val 4", "value 4")
		.option("val 5", "value 5")
		.less(3)
		.interact();

	let mut page_up_down = select("page up / down");
	page_up_down.less(10);

	for i in 0..100 {
		page_up_down.option(i, i);
	}

	let page_up_down = page_up_down.interact()?;

	outro!();

	println!("page_up_down {:?}", page_up_down);
	println!("select_less {:?}", select_less);
	println!("multi_less_noop {:?}", multi_less_noop);
	println!("multi_less {:?}", multi_less);

	Ok(())
}
source

pub fn options(&mut self, options: Vec<Opt<T, O>>) -> &mut Self

Add multiple options.

Examples
use may_clack::{multi_select, multi_select::Opt};

let opts = vec![
    Opt::simple("val1", "label 1"),
    Opt::hint("val2", "label 2", "hint"),
    Opt::simple("val3", "label 3")
];

let answer = multi_select("message").options(opts).interact();
println!("answer {:?}", answer);
source

pub fn less(&mut self, less: u16) -> &mut Self

Enable paging with the specified amount of lines.

Panics

Panics when the given value is 0.

Examples
use may_clack::multi_select;

let answer = multi_select("message")
    .option("val 1", "value 1")
    .option("val 2", "value 2")
    .option_hint("val 3", "value 3", "hint")
    .option("val 4", "value 4")
    .option("val 5", "value 5")
    .less(3)
    .interact();
println!("answer {:?}", answer);
Examples found in repository?
examples/less.rs (line 25)
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
44
45
46
47
48
49
50
51
52
53
54
fn main() -> Result<(), ClackError> {
	println!();
	intro!(style(" less ").reverse());

	let select_less = select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.option("val 4", "value 4")
		.option("val 5", "value 5")
		.less(3)
		.interact();

	let multi_less_noop = multi_select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.less(5)
		.interact();

	let multi_less = multi_select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.option("val 4", "value 4")
		.option("val 5", "value 5")
		.less(3)
		.interact();

	let mut page_up_down = select("page up / down");
	page_up_down.less(10);

	for i in 0..100 {
		page_up_down.option(i, i);
	}

	let page_up_down = page_up_down.interact()?;

	outro!();

	println!("page_up_down {:?}", page_up_down);
	println!("select_less {:?}", select_less);
	println!("multi_less_noop {:?}", multi_less_noop);
	println!("multi_less {:?}", multi_less);

	Ok(())
}
source

pub fn interact(&self) -> Result<Vec<T>, ClackError>

Wait for the user to submit the selected options.

Examples
use may_clack::multi_select;

let answer = multi_select("select")
    .option("val1", "value 1")
    .option("val2", "value 2")
    .option_hint("val 3", "value 3", "hint")
    .interact();
println!("answer {:?}", answer);
Examples found in repository?
examples/generic_select.rs (line 42)
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() -> Result<(), ClackError> {
	println!();
	intro!(style(" generic select ").reverse());

	let select_string = select("select string")
		.option("val1", SelectEnum::One)
		.option("val2", SelectEnum::One)
		.option("val3", SelectEnum::One)
		.interact()?;

	let select_enum = select("select enum")
		.option(SelectEnum::One, SelectEnum::One)
		.option(SelectEnum::Two, SelectEnum::Two)
		.option(SelectEnum::Three, SelectEnum::Three)
		.interact()?;

	let multi_enum = multi_select("multi_select enum")
		.option(SelectEnum::One, "one")
		.option(SelectEnum::Two, "two")
		.option(SelectEnum::Three, "three")
		.interact()?;

	outro!();

	println!("select string, label enum {:?}", select_string);
	println!("select enum, label enum {:?}", select_enum);
	println!("multi select enum, label string {:?}", multi_enum);

	Ok(())
}
More examples
Hide additional examples
examples/full.rs (line 26)
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
fn main() -> Result<(), ClackError> {
	println!();
	intro!(style(" full ").reverse());

	info!("visit the documentation at https://docs.rs/may-clack");

	let do_input = input("input")
		.default_value("default")
		.cancel(do_cancel)
		.interact()?;
	let do_multi_input = multi_input("multi input")
		.max(4)
		.cancel(do_cancel)
		.interact()?;
	let do_confirm = confirm("confirm").prompts("true", "false").interact()?;
	let do_multi_select = multi_select("multi select")
		.option("opt1", "option 1")
		.option("opt2", "option 2")
		.option_hint("opt3", "option 3", "hint")
		.interact()?;
	let do_select = select("select")
		.option("val1", "value 1")
		.option("val2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.interact()?;

	outro!();

	println!("input {:?}", do_input);
	println!("confirm {:?}", do_confirm);
	println!("multi_input {:?}", do_multi_input);
	println!("multi_select {:?}", do_multi_select);
	println!("select {:?}", do_select);

	Ok(())
}
examples/less.rs (line 26)
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
44
45
46
47
48
49
50
51
52
53
54
fn main() -> Result<(), ClackError> {
	println!();
	intro!(style(" less ").reverse());

	let select_less = select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.option("val 4", "value 4")
		.option("val 5", "value 5")
		.less(3)
		.interact();

	let multi_less_noop = multi_select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.less(5)
		.interact();

	let multi_less = multi_select("less")
		.option("val 1", "value 1")
		.option("val 2", "value 2")
		.option_hint("val 3", "value 3", "hint")
		.option("val 4", "value 4")
		.option("val 5", "value 5")
		.less(3)
		.interact();

	let mut page_up_down = select("page up / down");
	page_up_down.less(10);

	for i in 0..100 {
		page_up_down.option(i, i);
	}

	let page_up_down = page_up_down.interact()?;

	outro!();

	println!("page_up_down {:?}", page_up_down);
	println!("select_less {:?}", select_less);
	println!("multi_less_noop {:?}", multi_less_noop);
	println!("multi_less {:?}", multi_less);

	Ok(())
}

Trait Implementations§

source§

impl<M: Clone + Display, T: Clone + Clone, O: Clone + Display + Clone> Clone for MultiSelect<M, T, O>

source§

fn clone(&self) -> MultiSelect<M, T, O>

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<M: Debug + Display, T: Debug + Clone, O: Debug + Display + Clone> Debug for MultiSelect<M, T, O>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<M, T, O> RefUnwindSafe for MultiSelect<M, T, O>where M: RefUnwindSafe, O: RefUnwindSafe, T: RefUnwindSafe,

§

impl<M, T, O> Send for MultiSelect<M, T, O>where M: Send, O: Send, T: Send,

§

impl<M, T, O> Sync for MultiSelect<M, T, O>where M: Sync, O: Sync, T: Sync,

§

impl<M, T, O> Unpin for MultiSelect<M, T, O>where M: Unpin, O: Unpin, T: Unpin,

§

impl<M, T, O> UnwindSafe for MultiSelect<M, T, O>where M: UnwindSafe, O: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.