diff --git a/src/progress_bar.rs b/src/progress_bar.rs index fec1fd76..0c850e05 100644 --- a/src/progress_bar.rs +++ b/src/progress_bar.rs @@ -47,6 +47,18 @@ impl ProgressBar { Self::with_draw_target(Some(len), ProgressDrawTarget::stderr()) } + /// Creates a new progress bar without a specified length + /// + /// This progress bar by default draws directly to stderr, and refreshes a maximum of 20 times + /// a second. To change the refresh rate, [set] the [draw target] to one with a different refresh + /// rate. + /// + /// [set]: ProgressBar::set_draw_target + /// [draw target]: ProgressDrawTarget + pub fn no_length() -> Self { + Self::with_draw_target(None, ProgressDrawTarget::stderr()) + } + /// Creates a completely hidden progress bar /// /// This progress bar still responds to API changes but it does not have a length or render in @@ -263,6 +275,11 @@ impl ProgressBar { } } + /// Sets the length of the progress bar to `None` + pub fn unset_length(&self) { + self.state().unset_length(Instant::now()); + } + /// Sets the length of the progress bar pub fn set_length(&self, len: u64) { self.state().set_length(Instant::now(), len); diff --git a/src/state.rs b/src/state.rs index 136e2307..2f9100e2 100644 --- a/src/state.rs +++ b/src/state.rs @@ -96,6 +96,11 @@ impl BarState { } } + pub(crate) fn unset_length(&mut self, now: Instant) { + self.state.len = None; + self.update_estimate_and_draw(now); + } + pub(crate) fn set_length(&mut self, now: Instant, len: u64) { self.state.len = Some(len); self.update_estimate_and_draw(now);