Struct indicatif::ProgressBar[][src]

pub struct ProgressBar { /* fields omitted */ }
Expand description

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

Creates a new progress bar with a given length

This progress bar by default draws directly to stderr, and refreshes a maximum of 15 times a second. To change the refresh rate, set the draw target to one with a different refresh rate.

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.

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

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

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

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

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

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

Creates a new spinner

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

Overrides the stored style

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

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 (in milliseconds). 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.

Limit redrawing of progress bar to every n steps

By default, the progress bar will redraw whenever its state advances. This setting is helpful in situations where the overhead of redrawing the progress bar dominates the computation whose progress is being reported.

If n is greater than 0, operations that change the progress bar such as ProgressBar::tick(), ProgressBar::set_message() and ProgressBar::set_length() will no longer cause the progress bar to be redrawn, and will only be shown once the position advances by n steps.

let n = 1_000_000;
let pb = ProgressBar::new(n);
pb.set_draw_delta(n / 100); // redraw every 1% of additional progress

Note that ProgressDrawTarget may impose additional buffering of redraws.

Sets the refresh rate of progress bar to n updates per seconds

This is similar to set_draw_delta but automatically adapts to a constant refresh rate regardless of how consistent the progress is.

This parameter takes precedence on set_draw_delta if different from 0.

let n = 1_000_000;
let pb = ProgressBar::new(n);
pb.set_draw_rate(25); // aims at redrawing at most 25 times per seconds.

Note that the ProgressDrawTarget may impose additional buffering of redraws.

Manually ticks the spinner or progress bar

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

Advances the position of the progress bar by delta

A quick convenience check if the progress bar is hidden

Indicates that the progress bar finished

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 suspend instead.

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

Sets the position of the progress bar

Sets the length of the progress bar

Increase the length of the progress bar

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).

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).

Creates a new weak reference to this ProgressBar

Resets the ETA calculation

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

Resets elapsed time

Resets all of the progress bar state

Finishes the progress bar and leaves the current message

Finishes the progress bar at current position and leaves the current message

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).

Finishes the progress bar and completely clears it

Finishes the progress bar and leaves the current message and progress

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).

Finishes the progress bar using the behavior stored in the ProgressStyle

See ProgressStyle::on_finish().

Sets a different draw target for the progress bar

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

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.

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

Useful for external code that writes to the standard output.

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.

let mut pb = ProgressBar::new(3);
pb.suspend(|| {
    println!("Log message");
})

Wraps an Iterator with the progress bar

let v = vec![1, 2, 3];
let pb = ProgressBar::new(3);
for item in pb.wrap_iter(v.iter()) {
    // ...
}

Wraps an io::Read with the progress bar

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);

Wraps an io::Write with the progress bar

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));

Returns the current position

Returns the current length

Returns the current ETA

Returns the current rate of progress

Returns the current expected duration

Returns the current elapsed time

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.