-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathlib.rs
122 lines (114 loc) · 2.85 KB
/
lib.rs
1
2
3
4
5
6
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
extern crate pbr;
use pbr::{PbIter, ProgressBar};
use std::thread;
use std::time::Duration;
#[test]
fn simple_example() {
let count = 5000;
let mut pb = ProgressBar::new(count);
pb.format("╢▌▌░╟");
for _ in 0..count {
pb.inc();
thread::sleep(Duration::from_millis(5));
}
pb.finish_println("done!");
}
#[test]
fn custom_width_example() {
let count = 500;
let mut pb = ProgressBar::new(count);
pb.set_width(Some(80));
pb.format("╢▌▌░╟");
for _ in 0..count {
pb.inc();
thread::sleep(Duration::from_millis(5));
}
pb.finish_println("done!");
}
#[test]
fn simple_iter_example() {
for _ in PbIter::new(0..2000) {
thread::sleep(Duration::from_millis(1));
}
}
#[test]
fn timeout_example() {
let count = 10;
let mut pb = ProgressBar::new(count * 20);
pb.tick_format("▏▎▍▌▋▊▉██▉▊▋▌▍▎▏");
pb.show_message = true;
pb.inc();
for _ in 0..count {
for _ in 0..20 {
pb.message("Waiting : ");
thread::sleep(Duration::from_millis(50));
pb.tick();
}
for _ in 0..20 {
pb.message("Connected: ");
thread::sleep(Duration::from_millis(50));
pb.inc();
}
}
for _ in 0..10 {
pb.message("Cleaning :");
thread::sleep(Duration::from_millis(50));
pb.tick();
}
pb.finish_println("done!");
}
#[test]
// see: issue #11
fn tick_before_start() {
let count = 100;
let mut pb = ProgressBar::new(count);
pb.tick_format("▏▎▍▌▋▊▉██▉▊▋▌▍▎▏");
pb.tick();
for _ in 0..count {
pb.tick();
thread::sleep(Duration::from_millis(50));
}
for _ in 0..count {
pb.inc();
thread::sleep(Duration::from_millis(50));
}
}
#[test]
fn npm_bar() {
let count = 30;
let mut pb = ProgressBar::new(count * 5);
pb.tick_format("\\|/-");
pb.format("|#--|");
pb.show_tick = true;
pb.show_speed = false;
pb.show_percent = false;
pb.show_counter = false;
pb.show_time_left = false;
pb.inc();
for _ in 0..count {
for _ in 0..5 {
pb.message("normalize -> thing ");
thread::sleep(Duration::from_millis(80));
pb.tick();
}
for _ in 0..5 {
pb.message("fuzz -> tree ");
thread::sleep(Duration::from_millis(80));
pb.inc();
}
}
pb.finish_println("done!");
}
#[test]
// see: issue 45#
fn final_redraw_max_refresh_rate() {
let count = 500;
let mut pb = ProgressBar::new(count);
pb.format("╢▌▌░╟");
pb.set_max_refresh_rate(Some(Duration::from_millis(100)));
for _ in 0..count {
pb.inc();
thread::sleep(Duration::from_millis(5));
}
pb.finish_println("done!");
}