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 38af89d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 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

0 comments on commit 38af89d

Please sign in to comment.