pub struct MultiSelect<T> { /* private fields */ }Implementations§
Source§impl<T> MultiSelect<T>
impl<T> MultiSelect<T>
Sourcepub fn new(prompt: impl Into<String>) -> Self
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
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}Sourcepub fn option(self, label: impl Into<String>, value: T) -> Self
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
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}pub fn options(self, options: Vec<(String, T)>) -> Self
Sourcepub fn run(self) -> Result<Vec<T>>
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
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> 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