MultiSelect

Struct MultiSelect 

Source
pub struct MultiSelect<T> { /* private fields */ }

Implementations§

Source§

impl<T> MultiSelect<T>

Source

pub fn new(prompt: impl Into<String>) -> Self

Examples found in repository?
examples/multiselect_basic.rs (line 6)
3fn main() {
4    println!("=== MultiSelect Component Demo ===\n");
5
6    let result = MultiSelect::new("Select your favorite programming languages:")
7        .option("Rust", "rust")
8        .option("Python", "python")
9        .option("JavaScript", "javascript")
10        .option("Go", "go")
11        .option("TypeScript", "typescript")
12        .option("C++", "cpp")
13        .run();
14
15    match result {
16        Ok(languages) => {
17            println!("\nYou selected {} language(s):", languages.len());
18            for lang in languages {
19                println!("  - {}", lang);
20            }
21        }
22        Err(e) => eprintln!("\nError: {}", e),
23    }
24}
More examples
Hide additional examples
examples/p1_demo.rs (line 9)
5fn main() {
6    println!("=== P1 Components Demo ===\n");
7
8    // 1. MultiSelect
9    let languages = match MultiSelect::new("Select languages you know:")
10        .option("Rust", "rust")
11        .option("Python", "python")
12        .option("JavaScript", "javascript")
13        .option("Go", "go")
14        .run()
15    {
16        Ok(langs) => langs,
17        Err(e) => {
18            eprintln!("Error: {}", e);
19            return;
20        }
21    };
22
23    println!("\nSelected: {:?}\n", languages);
24
25    // 2. Spinner
26    let (spinner, handle) = Spinner::new("Analyzing your selections...");
27    let task = thread::spawn(move || {
28        thread::sleep(Duration::from_secs(2));
29        handle.finish();
30    });
31    spinner.run().unwrap();
32    task.join().unwrap();
33    println!("✓ Analysis complete\n");
34
35    // 3. ProgressBar
36    let (bar, handle) = ProgressBar::new(100, "Generating recommendations...");
37    let task = thread::spawn(move || {
38        for _ in 0..100 {
39            thread::sleep(Duration::from_millis(30));
40            handle.inc(1);
41        }
42        handle.finish();
43    });
44    bar.run().unwrap();
45    task.join().unwrap();
46    println!("✓ Recommendations ready\n");
47
48    // 4. Confirm
49    let save = match Confirm::new("Save your profile?").default(true).run() {
50        Ok(s) => s,
51        Err(e) => {
52            eprintln!("Error: {}", e);
53            return;
54        }
55    };
56
57    if save {
58        println!("\n✓ Profile saved!");
59    } else {
60        println!("\n✗ Profile not saved");
61    }
62}
Source

pub fn option(self, label: impl Into<String>, value: T) -> Self

Examples found in repository?
examples/multiselect_basic.rs (line 7)
3fn main() {
4    println!("=== MultiSelect Component Demo ===\n");
5
6    let result = MultiSelect::new("Select your favorite programming languages:")
7        .option("Rust", "rust")
8        .option("Python", "python")
9        .option("JavaScript", "javascript")
10        .option("Go", "go")
11        .option("TypeScript", "typescript")
12        .option("C++", "cpp")
13        .run();
14
15    match result {
16        Ok(languages) => {
17            println!("\nYou selected {} language(s):", languages.len());
18            for lang in languages {
19                println!("  - {}", lang);
20            }
21        }
22        Err(e) => eprintln!("\nError: {}", e),
23    }
24}
More examples
Hide additional examples
examples/p1_demo.rs (line 10)
5fn main() {
6    println!("=== P1 Components Demo ===\n");
7
8    // 1. MultiSelect
9    let languages = match MultiSelect::new("Select languages you know:")
10        .option("Rust", "rust")
11        .option("Python", "python")
12        .option("JavaScript", "javascript")
13        .option("Go", "go")
14        .run()
15    {
16        Ok(langs) => langs,
17        Err(e) => {
18            eprintln!("Error: {}", e);
19            return;
20        }
21    };
22
23    println!("\nSelected: {:?}\n", languages);
24
25    // 2. Spinner
26    let (spinner, handle) = Spinner::new("Analyzing your selections...");
27    let task = thread::spawn(move || {
28        thread::sleep(Duration::from_secs(2));
29        handle.finish();
30    });
31    spinner.run().unwrap();
32    task.join().unwrap();
33    println!("✓ Analysis complete\n");
34
35    // 3. ProgressBar
36    let (bar, handle) = ProgressBar::new(100, "Generating recommendations...");
37    let task = thread::spawn(move || {
38        for _ in 0..100 {
39            thread::sleep(Duration::from_millis(30));
40            handle.inc(1);
41        }
42        handle.finish();
43    });
44    bar.run().unwrap();
45    task.join().unwrap();
46    println!("✓ Recommendations ready\n");
47
48    // 4. Confirm
49    let save = match Confirm::new("Save your profile?").default(true).run() {
50        Ok(s) => s,
51        Err(e) => {
52            eprintln!("Error: {}", e);
53            return;
54        }
55    };
56
57    if save {
58        println!("\n✓ Profile saved!");
59    } else {
60        println!("\n✗ Profile not saved");
61    }
62}
Source

pub fn options(self, options: Vec<(String, T)>) -> Self

Source

pub fn run(self) -> Result<Vec<T>>

Examples found in repository?
examples/multiselect_basic.rs (line 13)
3fn main() {
4    println!("=== MultiSelect Component Demo ===\n");
5
6    let result = MultiSelect::new("Select your favorite programming languages:")
7        .option("Rust", "rust")
8        .option("Python", "python")
9        .option("JavaScript", "javascript")
10        .option("Go", "go")
11        .option("TypeScript", "typescript")
12        .option("C++", "cpp")
13        .run();
14
15    match result {
16        Ok(languages) => {
17            println!("\nYou selected {} language(s):", languages.len());
18            for lang in languages {
19                println!("  - {}", lang);
20            }
21        }
22        Err(e) => eprintln!("\nError: {}", e),
23    }
24}
More examples
Hide additional examples
examples/p1_demo.rs (line 14)
5fn main() {
6    println!("=== P1 Components Demo ===\n");
7
8    // 1. MultiSelect
9    let languages = match MultiSelect::new("Select languages you know:")
10        .option("Rust", "rust")
11        .option("Python", "python")
12        .option("JavaScript", "javascript")
13        .option("Go", "go")
14        .run()
15    {
16        Ok(langs) => langs,
17        Err(e) => {
18            eprintln!("Error: {}", e);
19            return;
20        }
21    };
22
23    println!("\nSelected: {:?}\n", languages);
24
25    // 2. Spinner
26    let (spinner, handle) = Spinner::new("Analyzing your selections...");
27    let task = thread::spawn(move || {
28        thread::sleep(Duration::from_secs(2));
29        handle.finish();
30    });
31    spinner.run().unwrap();
32    task.join().unwrap();
33    println!("✓ Analysis complete\n");
34
35    // 3. ProgressBar
36    let (bar, handle) = ProgressBar::new(100, "Generating recommendations...");
37    let task = thread::spawn(move || {
38        for _ in 0..100 {
39            thread::sleep(Duration::from_millis(30));
40            handle.inc(1);
41        }
42        handle.finish();
43    });
44    bar.run().unwrap();
45    task.join().unwrap();
46    println!("✓ Recommendations ready\n");
47
48    // 4. Confirm
49    let save = match Confirm::new("Save your profile?").default(true).run() {
50        Ok(s) => s,
51        Err(e) => {
52            eprintln!("Error: {}", e);
53            return;
54        }
55    };
56
57    if save {
58        println!("\n✓ Profile saved!");
59    } else {
60        println!("\n✗ Profile not saved");
61    }
62}

Auto Trait Implementations§

§

impl<T> Freeze for MultiSelect<T>

§

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

§

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

§

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

§

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

§

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

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