diff --git a/src/state.rs b/src/state.rs index a3228c81..fb7de2be 100644 --- a/src/state.rs +++ b/src/state.rs @@ -385,6 +385,11 @@ impl Estimator { fn record(&mut self, new: u64, now: Instant) { let delta = new.saturating_sub(self.prev.0); if delta == 0 || now < self.prev.1 { + // Reset on backwards seek to prevent breakage from seeking to the end for length determination + // See https://github.com/console-rs/indicatif/issues/480 + if new < self.prev.0 { + self.reset(now); + } return; } @@ -617,8 +622,11 @@ mod tests { let mut est = Estimator::new(now); est.record(0, now); est.record(1, now); + assert_eq!(est.len(), 1); // Should not panic. est.record(0, now); + // Assert that the state of the estimator reset on rewind + assert_eq!(est.len(), 0); let pb = ProgressBar::hidden(); pb.set_length(10);