extern crate progrs; use std::cmp::min; use std::thread::sleep; use std::time::{Instant, Duration}; // An example of git-like progress reporting while receiving messages // and objects from remote and locally. // remote: Counting objects: 218676, done. // remote: Compressing objects: 100% (58659/58659), done. // remote: Total 218676 (delta 162851), reused 213808 (delta 158032) // Receiving objects: 100% (218676/218676), 90.83 MiB | 31.39 MiB/s, done. // Resolving deltas: 100% (162851/162851), done. fn main() { let mut p = progrs::start("remote: Counting objects", None); let nobjects = 218676; let ncompress = 58659; let ndeltas = 162851; let mut total = 0u64; while total < nobjects { let now = Instant::now(); sleep(Duration::new(1, 0)); let elapsed = now.elapsed(); total = min(total + elapsed.subsec_nanos() as u64 / 5, nobjects); p.display(total); } p.stop("done"); let mut p = progrs::start("remote: Compressing objects", Some(ncompress)); total = 0; while total < ncompress { let now = Instant::now(); sleep(Duration::from_millis(1)); total = min(total + now.elapsed().subsec_nanos() as u64 / 10000, ncompress); p.display(total); } p.stop("done"); println!("remote: Total {} (delta {}), reused 213808 (delta 158032)", nobjects, ndeltas); sleep(Duration::from_millis(500)); let mut p = progrs::start("Receiving objects", Some(nobjects)); total = 0; while total < nobjects { let now = Instant::now(); sleep(Duration::from_millis(100)); total = min(total + now.elapsed().subsec_nanos() as u64 / 30000, nobjects); p.display(total); } p.stop("done"); sleep(Duration::from_millis(500)); let mut p = progrs::start("Resolving deltas", Some(ndeltas)); total = 0; while total < ndeltas { let now = Instant::now(); sleep(Duration::new(0, 3000)); total = min(total + now.elapsed().subsec_nanos() as u64 / 3000, ndeltas); p.display(total); } p.stop("done"); }