diff --git a/src/state.rs b/src/state.rs index 8c974a25..d816b110 100644 --- a/src/state.rs +++ b/src/state.rs @@ -421,13 +421,16 @@ impl ProgressDrawTarget { /// /// Will panic if refresh_rate is `Some(0)`. To disable rate limiting use `None` instead. pub fn term(term: Term, refresh_rate: impl Into>) -> ProgressDrawTarget { - let rate = refresh_rate.into().map(|x| Duration::from_millis(1000 / x)); + let rate = refresh_rate + .into() + .map(|x| Duration::from_millis(1000 / x)) + .unwrap_or_else(|| Duration::from_secs(0)); ProgressDrawTarget { kind: ProgressDrawTargetKind::Term { term, last_state: None, rate, - last_draw: None, + last_draw: Instant::now() - rate, }, } } @@ -477,9 +480,8 @@ impl ProgressDrawTarget { } => { if draw_state.finished || draw_state.force_draw - || rate.is_none() - || last_draw.is_none() - || last_draw.unwrap().elapsed() > rate.unwrap() + || rate == Duration::from_secs(0) + || last_draw.elapsed() > rate { if let Some(ref last_state) = *last_state { if !draw_state.lines.is_empty() && draw_state.move_cursor { @@ -491,7 +493,7 @@ impl ProgressDrawTarget { draw_state.draw_to_term(term)?; term.flush()?; *last_state = Some(draw_state); - *last_draw = Some(Instant::now()); + *last_draw = Instant::now(); } } ProgressDrawTargetKind::Remote { idx, ref chan, .. } => { @@ -533,8 +535,8 @@ pub(crate) enum ProgressDrawTargetKind { Term { term: Term, last_state: Option, - rate: Option, - last_draw: Option, + rate: Duration, + last_draw: Instant, }, Remote { state: Arc>,