Skip to content

Commit

Permalink
Only tick if the ticker is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Aug 3, 2022
1 parent 20a857a commit d82a11d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/progress_bar.rs
Expand Up @@ -201,7 +201,7 @@ impl ProgressBar {
pub fn inc(&self, delta: u64) {
self.pos.inc(delta);
let now = Instant::now();
if self.pos.allow(now) {
if self.pos.allow(now) && self.ticker.lock().unwrap().is_none() {
self.state().tick(now);
}
}
Expand Down Expand Up @@ -233,14 +233,15 @@ impl ProgressBar {

/// Update the `ProgressBar`'s inner [`ProgressState`]
pub fn update(&self, f: impl FnOnce(&mut ProgressState)) {
self.state().update(Instant::now(), f)
self.state()
.update(Instant::now(), f, self.ticker.lock().unwrap().is_none())
}

/// Sets the position of the progress bar
pub fn set_position(&self, pos: u64) {
self.pos.set(pos);
let now = Instant::now();
if self.pos.allow(now) {
if self.pos.allow(now) && self.ticker.lock().unwrap().is_none() {
self.state().tick(now);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/state.rs
Expand Up @@ -84,9 +84,11 @@ impl BarState {
}
}

pub(crate) fn update(&mut self, now: Instant, f: impl FnOnce(&mut ProgressState)) {
pub(crate) fn update(&mut self, now: Instant, f: impl FnOnce(&mut ProgressState), tick: bool) {
f(&mut self.state);
self.tick(now);
if tick {
self.tick(now);
}
}

pub(crate) fn set_length(&mut self, now: Instant, len: u64) {
Expand Down
2 changes: 1 addition & 1 deletion tests/render.rs
Expand Up @@ -339,7 +339,7 @@ fn ticker_drop() {
.with_finish(ProgressFinish::AndLeave)
.with_message(format!("doing stuff {}", i)),
);
new_spinner.enable_steady_tick(Duration::from_millis(50));
new_spinner.enable_steady_tick(Duration::from_millis(100));
spinner.replace(new_spinner);
}

Expand Down

0 comments on commit d82a11d

Please sign in to comment.