Struct ProgressBar

struct ProgressBar { ... }

A progress bar or spinner

The progress bar is an Arc around its internal state. When the progress bar is cloned it just increments the refcount (so the original and its clone share the same state).

Implementations

impl ProgressBar

fn new(len: u64) -> Self

Creates a new progress bar with a given 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.

fn no_length() -> Self

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.

fn hidden() -> Self

Creates a completely hidden progress bar

This progress bar still responds to API changes but it does not have a length or render in any way.

fn with_draw_target(len: Option<u64>, draw_target: ProgressDrawTarget) -> Self

Creates a new progress bar with a given length and draw target

fn style(self: &Self) -> ProgressStyle

Get a clone of the current progress bar style.

fn with_style(self: Self, style: ProgressStyle) -> Self

A convenience builder-like function for a progress bar with a given style

fn with_tab_width(self: Self, tab_width: usize) -> Self

A convenience builder-like function for a progress bar with a given tab width

fn with_prefix<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: Self, prefix: impl Into<Cow<'static, str>>) -> Self

A convenience builder-like function for a progress bar with a given prefix

For the prefix to be visible, the {prefix} placeholder must be present in the template (see ProgressStyle).

fn with_message<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: Self, message: impl Into<Cow<'static, str>>) -> Self

A convenience builder-like function for a progress bar with a given message

For the message to be visible, the {msg} placeholder must be present in the template (see ProgressStyle).

fn with_position(self: Self, pos: u64) -> Self

A convenience builder-like function for a progress bar with a given position

fn with_elapsed(self: Self, elapsed: Duration) -> Self

A convenience builder-like function for a progress bar with a given elapsed time

fn with_finish(self: Self, finish: ProgressFinish) -> Self

Sets the finish behavior for the progress bar

This behavior is invoked when ProgressBar or ProgressBarIter completes and ProgressBar::is_finished() is false. If you don't want the progress bar to be automatically finished then call with_finish(Abandon).

fn new_spinner() -> Self

Creates a new spinner

This spinner by default draws directly to stderr. This adds the default spinner style to it.

fn set_style(self: &Self, style: ProgressStyle)

Overrides the stored style

This does not redraw the bar. Call [ProgressBar::tick()] to force it.

fn set_tab_width(self: &Self, tab_width: usize)

Sets the tab width (default: 8). All tabs will be expanded to this many spaces.

fn enable_steady_tick(self: &Self, interval: Duration)

Spawns a background thread to tick the progress bar

When this is enabled a background thread will regularly tick the progress bar in the given interval. This is useful to advance progress bars that are very slow by themselves.

When steady ticks are enabled, calling [ProgressBar::tick()] on a progress bar does not have any effect.

fn disable_steady_tick(self: &Self)

Undoes [ProgressBar::enable_steady_tick()]

fn tick(self: &Self)

Manually ticks the spinner or progress bar

This automatically happens on any other change to a progress bar.

fn inc(self: &Self, delta: u64)

Advances the position of the progress bar by delta

fn dec(self: &Self, delta: u64)

Decrease the position of the progress bar by delta

fn is_hidden(self: &Self) -> bool

A quick convenience check if the progress bar is hidden

fn is_finished(self: &Self) -> bool

Indicates that the progress bar finished

fn println<I: AsRef<str>>(self: &Self, msg: I)

Print a log line above the progress bar

If the progress bar is hidden (e.g. when standard output is not a terminal), println() will not do anything. If you want to write to the standard output in such cases as well, use ProgressBar::suspend() instead.

If the progress bar was added to a MultiProgress, the log line will be printed above all other progress bars.

fn update<impl FnOnce(&mut ProgressState): FnOnce(&mut ProgressState)>(self: &Self, f: impl FnOnce(&mut ProgressState))

Update the ProgressBar's inner ProgressState

fn set_position(self: &Self, pos: u64)

Sets the position of the progress bar

fn unset_length(self: &Self)

Sets the length of the progress bar to None

fn set_length(self: &Self, len: u64)

Sets the length of the progress bar

fn inc_length(self: &Self, delta: u64)

Increase the length of the progress bar

fn dec_length(self: &Self, delta: u64)

Decrease the length of the progress bar

fn set_prefix<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: &Self, prefix: impl Into<Cow<'static, str>>)

Sets the current prefix of the progress bar

For the prefix to be visible, the {prefix} placeholder must be present in the template (see ProgressStyle).

fn set_message<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: &Self, msg: impl Into<Cow<'static, str>>)

Sets the current message of the progress bar

For the message to be visible, the {msg} placeholder must be present in the template (see ProgressStyle).

fn set_elapsed(self: &Self, elapsed: Duration)

Sets the elapsed time for the progress bar

fn downgrade(self: &Self) -> WeakProgressBar

Creates a new weak reference to this ProgressBar

fn reset_eta(self: &Self)

Resets the ETA calculation

This can be useful if the progress bars made a large jump or was paused for a prolonged time.

fn reset_elapsed(self: &Self)

Resets elapsed time and the ETA calculation

fn reset(self: &Self)

Resets all of the progress bar state

fn finish(self: &Self)

Finishes the progress bar and leaves the current message

fn finish_with_message<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: &Self, msg: impl Into<Cow<'static, str>>)

Finishes the progress bar and sets a message

For the message to be visible, the {msg} placeholder must be present in the template (see ProgressStyle).

fn finish_and_clear(self: &Self)

Finishes the progress bar and completely clears it

fn abandon(self: &Self)

Finishes the progress bar and leaves the current message and progress

fn abandon_with_message<impl Into<Cow<'static, str>>: Into<Cow<'static, str>>>(self: &Self, msg: impl Into<Cow<'static, str>>)

Finishes the progress bar and sets a message, and leaves the current progress

For the message to be visible, the {msg} placeholder must be present in the template (see ProgressStyle).

fn finish_using_style(self: &Self)

Finishes the progress bar using the behavior stored in the ProgressStyle

See [ProgressBar::with_finish()].

fn set_draw_target(self: &Self, target: ProgressDrawTarget)

Sets a different draw target for the progress bar

This can be used to draw the progress bar to stderr (this is the default):

# use indicatif::{ProgressBar, ProgressDrawTarget};
let pb = ProgressBar::new(100);
pb.set_draw_target(ProgressDrawTarget::stderr());

Note: Calling this method on a ProgressBar linked with a MultiProgress (after running MultiProgress::add()) will unlink this progress bar. If you don't want this behavior, call MultiProgress::set_draw_target() instead.

Use [ProgressBar::with_draw_target()] to set the draw target during creation.

fn force_draw(self: &Self)

Force a redraw of the progress bar to be in sync with its state

For performance reasons the progress bar is not redrawn on each state update. This is normally not an issue, since new updates will eventually trigger rendering.

For slow running tasks it is recommended to rely on [ProgressBar::enable_steady_tick()] to ensure continued rendering of the progress bar.

fn suspend<F: FnOnce() -> R, R>(self: &Self, f: F) -> R

Hide the progress bar temporarily, execute f, then redraw the progress bar

Useful for external code that writes to the standard output.

If the progress bar was added to a MultiProgress, it will suspend the entire MultiProgress.

Note: The internal lock is held while f is executed. Other threads trying to print anything on the progress bar will be blocked until f finishes. Therefore, it is recommended to avoid long-running operations in f.

# use indicatif::ProgressBar;
let mut pb = ProgressBar::new(3);
pb.suspend(|| {
    println!("Log message");
})
fn wrap_iter<It: Iterator>(self: &Self, it: It) -> ProgressBarIter<It>

Wraps an Iterator with the progress bar

# use indicatif::ProgressBar;
let v = vec![1, 2, 3];
let pb = ProgressBar::new(3);
for item in pb.wrap_iter(v.iter()) {
    // ...
}
fn wrap_read<R: io::Read>(self: &Self, read: R) -> ProgressBarIter<R>

Wraps an io::Read with the progress bar

# use std::fs::File;
# use std::io;
# use indicatif::ProgressBar;
# fn test () -> io::Result<()> {
let source = File::open("work.txt")?;
let mut target = File::create("done.txt")?;
let pb = ProgressBar::new(source.metadata()?.len());
io::copy(&mut pb.wrap_read(source), &mut target);
# Ok(())
# }
fn wrap_write<W: io::Write>(self: &Self, write: W) -> ProgressBarIter<W>

Wraps an io::Write with the progress bar

# use std::fs::File;
# use std::io;
# use indicatif::ProgressBar;
# fn test () -> io::Result<()> {
let mut source = File::open("work.txt")?;
let target = File::create("done.txt")?;
let pb = ProgressBar::new(source.metadata()?.len());
io::copy(&mut source, &mut pb.wrap_write(target));
# Ok(())
# }
fn position(self: &Self) -> u64

Returns the current position

fn length(self: &Self) -> Option<u64>

Returns the current length

fn eta(self: &Self) -> Duration

Returns the current ETA

fn per_sec(self: &Self) -> f64

Returns the current rate of progress

fn duration(self: &Self) -> Duration

Returns the current expected duration

fn elapsed(self: &Self) -> Duration

Returns the current elapsed time

fn message(self: &Self) -> String

Current message

fn prefix(self: &Self) -> String

Current prefix

impl Clone for ProgressBar

fn clone(self: &Self) -> ProgressBar

impl Debug for ProgressBar

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Freeze for ProgressBar

impl RefUnwindSafe for ProgressBar

impl Send for ProgressBar

impl Sync for ProgressBar

impl Unpin for ProgressBar

impl UnsafeUnpin for ProgressBar

impl UnwindSafe for ProgressBar

impl<T> Any for ProgressBar

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ProgressBar

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for ProgressBar

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for ProgressBar

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for ProgressBar

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for ProgressBar

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for ProgressBar

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for ProgressBar

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for ProgressBar

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>