From ffb5d50a6f873609f97d641ce2345398a6f820e5 Mon Sep 17 00:00:00 2001 From: Yann Date: Thu, 29 Jun 2017 09:19:44 +0200 Subject: [PATCH] Fix No final redraw when max_refresh_rate is set --- src/pb.rs | 2 +- tests/lib.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/pb.rs b/src/pb.rs index 461823f7..60b732cc 100644 --- a/src/pb.rs +++ b/src/pb.rs @@ -309,7 +309,7 @@ impl ProgressBar { fn draw(&mut self) { let now = SteadyTime::now(); if let Some(mrr) = self.max_refresh_rate { - if now - self.last_refresh_time < mrr { + if now - self.last_refresh_time < mrr && self.current < self.total { return; } } diff --git a/tests/lib.rs b/tests/lib.rs index 4c291343..dd1bc563 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -107,3 +107,18 @@ fn npm_bar() { } pb.finish_println("done!"); } + +#[test] +// see: issue 45# +fn final_redraw_max_refresh_rate() { + let count = 500; + let mut pb = ProgressBar::new(count); + pb.format("╢▌▌░╟"); + pb.set_max_refresh_rate(Some(Duration::from_millis(100))); + for _ in 0..count { + pb.inc(); + thread::sleep(Duration::from_millis(5)); + } + pb.finish_println("done!"); +} +