syncbox/utils/
progress.rs1use indicatif::{ProgressBar, ProgressStyle, ProgressState};
2use std::fmt::Write;
3use crate::utils::format::format_file_size;
4
5pub fn create_progress_bar(total: u64) -> ProgressBar {
7 let pb = ProgressBar::new(total);
8 pb.set_style(
9 ProgressStyle::with_template(
10 "{spinner:.green} [{elapsed_precise}] [{bar:50.cyan/blue}] {bytes_human}/{total_bytes_human} ({eta})"
11 )
12 .unwrap()
13 .with_key("eta", |state: &ProgressState, w: &mut dyn Write| {
14 write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap()
15 })
16 .with_key("bytes_human", |state: &ProgressState, w: &mut dyn Write| {
17 write!(w, "{}", format_file_size(state.pos() as u64)).unwrap()
18 })
19 .with_key("total_bytes_human", |state: &ProgressState, w: &mut dyn Write| {
20 write!(w, "{}", format_file_size(state.len().unwrap() as u64)).unwrap()
21 })
22 .progress_chars("#>-")
23 );
24 pb
25}