1use progressing::{
2 bernoulli::Bar as BernoulliBar, clamping::Bar as ClampingBar, mapping::Bar as MappingBar,
3 Baring,
4};
5use std::{thread, time};
6
7const SLEEP_MS: u64 = 20;
8
9fn main() {
10 clamped();
12 println!();
13 mapped();
14 println!();
15 bernoulli();
16}
17
18fn clamped() {
19 let min_value = -80;
20 let max_value = 180;
21
22 println!(
23 "The bar is running from {} % to {} % clamping to [0, 1].",
24 min_value, max_value
25 );
26 println!(
27 "{}{}",
28 "Note the respective pause at the beginning and the end, ",
29 "which causes the approximated time to be too high."
30 );
31
32 let mut progress_bar = ClampingBar::new().timed();
34
35 for value in min_value..(max_value + 1) {
37 progress_bar.set(value as f32 / 100.0);
38 if progress_bar.has_progressed_significantly() {
39 progress_bar.remember_significant_progress();
40 println!("{}", progress_bar);
41 }
42
43 thread::sleep(time::Duration::from_millis(SLEEP_MS));
45 }
46 println!("{}", progress_bar);
48}
49
50fn mapped() {
51 let min_value = -10;
52 let max_value = 100;
53 let min_bar_border = -40;
54 let max_bar_border = 140;
55
56 println!(
57 "The bar is running from {} to {}, but maps [{}, {}] to [0, 1].",
58 min_value, max_value, min_bar_border, max_bar_border
59 );
60 println!("Note that the bar neither starts nor ends at the bar-borders.");
61
62 let mut progress_bar = MappingBar::with_range(min_bar_border, max_bar_border).timed();
64
65 for value in min_value..(max_value + 1) {
67 progress_bar.set(value);
68 if progress_bar.has_progressed_significantly() {
69 progress_bar.remember_significant_progress();
70 println!("{}", progress_bar);
71 }
72
73 thread::sleep(time::Duration::from_millis(SLEEP_MS));
75 }
76 println!("{}", progress_bar);
78}
79
80fn bernoulli() {
81 let min_value = -50;
82 let max_value = 120;
83
84 println!(
85 "The bar is running from {} to {} counting successes (if value is even) and attempts ({}).",
86 min_value,
87 max_value,
88 (max_value - min_value) + 1
89 );
90 println!("Note that the bar expects less successes than provided .");
91
92 let mut progress_bar = BernoulliBar::with_goal(60).timed();
94 progress_bar.set_len(60);
96
97 for value in min_value..(max_value + 1) {
99 let is_successful = value % 2 == 0;
101 progress_bar.add(is_successful);
102 if progress_bar.has_progressed_significantly() {
103 progress_bar.remember_significant_progress();
104 println!("{}", progress_bar);
105 }
106
107 thread::sleep(time::Duration::from_millis(SLEEP_MS));
109 }
110 println!("{}", progress_bar);
112}