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
|
# just_progress
> Just a progress display tool
## Usage
```rust
use just_progress::progress;
use just_progress::renderer::ProgressSimpleRenderer;
use tokio::time::{sleep, Duration};
use tokio::join;
#[tokio::main]
async fn main() {
// Initialize the progress center
let center = progress::init();
// Create a renderer and enable subprogress display
let renderer = ProgressSimpleRenderer::new().with_subprogress(true);
// Bind the renderer callback function
let bind = progress::bind(center, move |name, state| renderer.update(name, state));
// Concurrently execute progress binding and business logic
join!(bind, proc());
}
async fn proc() {
println!("Starting package download!");
sleep(Duration::from_millis(500)).await;
// Define multiple concurrent download tasks
let download_task = async {
for i in 1..21 {
sleep(Duration::from_millis(50)).await;
progress::update_progress("Download/Data", i as f32 * 0.05);
}
};
let extract_task = async {
for i in 1..11 {
sleep(Duration::from_millis(100)).await;
progress::update_progress("Download/Extract", i as f32 * 0.1);
}
};
let verify_sha256_task = async {
for i in 1..6 {
sleep(Duration::from_millis(300)).await;
progress::update_progress("Download/Verify/SHA256", i as f32 * 0.2);
}
};
let verify_md5_task = async {
for i in 1..6 {
sleep(Duration::from_millis(100)).await;
progress::update_progress("Download/Verify/MD5", i as f32 * 0.2);
}
};
let verify_blake3_task = async {
for i in 1..6 {
sleep(Duration::from_millis(500)).await;
progress::update_progress("Download/Verify/Blake3", i as f32 * 0.2);
}
};
// Concurrently execute all download tasks
join!(
download_task,
extract_task,
verify_sha256_task,
verify_blake3_task,
verify_md5_task
);
sleep(Duration::from_millis(500)).await;
progress::clear_all(); // Clear all progress after download completes
println!("Package download complete!");
progress::close(); // Close the progress channel, ending the program
}
```
## Installation
Add this to your `Cargo.toml`:
```toml
[dependencies]
just_progress = "0.1"
```
## License
This project is dual-licensed under MIT and Apache 2.0.
See the LICENSE file for details.
|