1use cli_animate::interactive_menu::{InteractiveMenu, StyleBuilder as InteractiveMenuStyleBuilder};
2use cli_animate::loading_indicator::LoadingIndicator;
3use cli_animate::progress::{ProgressBar, StyleBuilder as ProgressBarStyleBuilder};
4use cli_animate::utils::Color;
5use std::sync::{Arc, Mutex};
6use std::{thread, time};
7
8fn main() {
10 let progress_value = Arc::new(Mutex::new(0));
15
16 let thread_progress_value = progress_value.clone();
18
19 let do_some_work = thread::spawn(move || {
21 let mut num = 0;
22 while num <= 100 {
23 thread::sleep(time::Duration::from_millis(20));
24
25 let mut val = thread_progress_value.lock().unwrap();
26 *val = num;
27
28 num += 1;
29 }
30 });
31
32 let style = ProgressBarStyleBuilder::new() .color(Color::Green)
35 .bar_length(60)
36 .build();
37 let progress_bar = ProgressBar::new(0, 100, move || *progress_value.lock().unwrap(), style);
38
39 let mut writer = std::io::stdout();
40
41 progress_bar.start(&mut writer);
43
44 do_some_work.join().unwrap();
46
47 let options = vec![
52 "Tokyo".to_string(),
53 "Saitama".to_string(),
54 "Kanagawa".to_string(),
55 ];
56
57 let mut menu = InteractiveMenu::new(
59 options.clone(),
60 InteractiveMenuStyleBuilder::new() .color(Color::Blue)
62 .selected_prefix('*')
63 .build(),
64 );
65
66 let selected_index = menu.run().unwrap();
68
69 println!("You selected: {}", options[selected_index]);
70
71 let loading_indicator = LoadingIndicator::new(Color::Red);
76 loading_indicator.start();
77
78 let mut num = 0;
80 while num <= 100 {
81 thread::sleep(time::Duration::from_millis(20));
82 num += 1;
83 }
84
85 loading_indicator.stop();
87}