Struct may_clack::multi_select::MultiSelect
source · 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>
impl<M: Display, T: Clone, O: Display + Clone> MultiSelect<M, T, O>
sourcepub fn new(message: M) -> Self
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");sourcepub fn option(&mut self, val: T, label: O) -> &mut Self
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
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(())
}sourcepub fn option_hint<S: Into<String>>(
&mut self,
val: T,
label: O,
hint: S
) -> &mut Self
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
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(())
}sourcepub fn options(&mut self, options: Vec<Opt<T, O>>) -> &mut Self
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);sourcepub fn less(&mut self, less: u16) -> &mut Self
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(())
}sourcepub fn interact(&self) -> Result<Vec<T>, ClackError>
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
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§
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> 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
Mutably borrows from an owned value. Read more