| 1 |
use std::thread; |
| 2 |
use std::time::Duration; |
| 3 |
use std::{cmp::min, fmt::Write}; |
| 4 |
|
| 5 |
use indicatif::{ProgressBar, ProgressState, 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} ({eta})") |
| 13 |
.unwrap() |
| 14 |
.with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap()) |
| 15 |
.progress_chars("#>-")); |
| 16 |
|
| 17 |
while downloaded < total_size { |
| 18 |
let new = min(downloaded + 223211, total_size); |
| 19 |
downloaded = new; |
| 20 |
pb.set_position(new); |
| 21 |
thread::sleep(Duration::from_millis(12)); |
| 22 |
} |
| 23 |
|
| 24 |
pb.finish_with_message("downloaded"); |
| 25 |
} |