| 1 |
use std::cmp::min; |
| 2 |
use std::thread; |
| 3 |
use std::time::Duration; |
| 4 |
|
| 5 |
use indicatif::{ProgressBar, ProgressStyle}; |
| 6 |
|
| 7 |
fn main() { |
| 8 |
let mut downloaded = 0; |
| 9 |
let total_size = 231231231; |
| 10 |
|
| 11 |
let pb = ProgressBar::new(total_size); |
| 12 |
pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})") |
| 13 |
.unwrap() |
| 14 |
.progress_chars("#>-")); |
| 15 |
|
| 16 |
while downloaded < total_size { |
| 17 |
let new = min(downloaded + 223211, total_size); |
| 18 |
downloaded = new; |
| 19 |
pb.set_position(new); |
| 20 |
thread::sleep(Duration::from_millis(12)); |
| 21 |
} |
| 22 |
|
| 23 |
pb.finish_with_message("downloaded"); |
| 24 |
} |