pub struct PROGRESS_BAR { /* private fields */ }
Expand description
Lazily initialized progress bar.
Methods from Deref<Target = ProgressBar>§
Sourcepub fn style(&self) -> ProgressStyle
pub fn style(&self) -> ProgressStyle
Get a clone of the current progress bar style.
Sourcepub fn set_style(&self, style: ProgressStyle)
pub fn set_style(&self, style: ProgressStyle)
Overrides the stored style
This does not redraw the bar. Call ProgressBar::tick()
to force it.
Sourcepub fn set_tab_width(&self, tab_width: usize)
pub fn set_tab_width(&self, tab_width: usize)
Sets the tab width (default: 8). All tabs will be expanded to this many spaces.
Sourcepub fn enable_steady_tick(&self, interval: Duration)
pub fn enable_steady_tick(&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.
Sourcepub fn disable_steady_tick(&self)
pub fn disable_steady_tick(&self)
Sourcepub fn tick(&self)
pub fn tick(&self)
Manually ticks the spinner or progress bar
This automatically happens on any other change to a progress bar.
A quick convenience check if the progress bar is hidden
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Indicates that the progress bar finished
Sourcepub fn println<I>(&self, msg: I)
pub fn println<I>(&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.
Sourcepub fn update(&self, f: impl FnOnce(&mut ProgressState))
pub fn update(&self, f: impl FnOnce(&mut ProgressState))
Update the ProgressBar
’s inner ProgressState
Sourcepub fn set_position(&self, pos: u64)
pub fn set_position(&self, pos: u64)
Sets the position of the progress bar
Sourcepub fn unset_length(&self)
pub fn unset_length(&self)
Sets the length of the progress bar to None
Sourcepub fn set_length(&self, len: u64)
pub fn set_length(&self, len: u64)
Sets the length of the progress bar
Sourcepub fn inc_length(&self, delta: u64)
pub fn inc_length(&self, delta: u64)
Increase the length of the progress bar
Sourcepub fn dec_length(&self, delta: u64)
pub fn dec_length(&self, delta: u64)
Decrease the length of the progress bar
Sourcepub fn set_prefix(&self, prefix: impl Into<Cow<'static, str>>)
pub fn set_prefix(&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
).
Sourcepub fn set_message(&self, msg: impl Into<Cow<'static, str>>)
pub fn set_message(&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
).
Sourcepub fn downgrade(&self) -> WeakProgressBar
pub fn downgrade(&self) -> WeakProgressBar
Creates a new weak reference to this ProgressBar
Sourcepub fn reset_eta(&self)
pub fn reset_eta(&self)
Resets the ETA calculation
This can be useful if the progress bars made a large jump or was paused for a prolonged time.
Sourcepub fn reset_elapsed(&self)
pub fn reset_elapsed(&self)
Resets elapsed time and the ETA calculation
Sourcepub fn finish_with_message(&self, msg: impl Into<Cow<'static, str>>)
pub fn finish_with_message(&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
).
Sourcepub fn finish_and_clear(&self)
pub fn finish_and_clear(&self)
Finishes the progress bar and completely clears it
Sourcepub fn abandon_with_message(&self, msg: impl Into<Cow<'static, str>>)
pub fn abandon_with_message(&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
).
Sourcepub fn finish_using_style(&self)
pub fn finish_using_style(&self)
Finishes the progress bar using the behavior stored in the ProgressStyle
Sourcepub fn set_draw_target(&self, target: ProgressDrawTarget)
pub fn set_draw_target(&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):
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.
Sourcepub fn suspend<F, R>(&self, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn suspend<F, R>(&self, f: F) -> Rwhere
F: FnOnce() -> 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
.
let mut pb = ProgressBar::new(3);
pb.suspend(|| {
println!("Log message");
})
Sourcepub fn wrap_iter<It>(&self, it: It) -> ProgressBarIter<It>where
It: Iterator,
pub fn wrap_iter<It>(&self, it: It) -> ProgressBarIter<It>where
It: Iterator,
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()) {
// ...
}
Sourcepub fn wrap_read<R>(&self, read: R) -> ProgressBarIter<R>where
R: Read,
pub fn wrap_read<R>(&self, read: R) -> ProgressBarIter<R>where
R: Read,
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);
Sourcepub fn wrap_write<W>(&self, write: W) -> ProgressBarIter<W>where
W: Write,
pub fn wrap_write<W>(&self, write: W) -> ProgressBarIter<W>where
W: Write,
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));
Trait Implementations§
Source§impl Deref for PROGRESS_BAR
impl Deref for PROGRESS_BAR
Source§type Target = ProgressBar
type Target = ProgressBar
Source§fn deref(&self) -> &ProgressBar
fn deref(&self) -> &ProgressBar
impl LazyStatic for PROGRESS_BAR
Auto Trait Implementations§
impl Freeze for PROGRESS_BAR
impl RefUnwindSafe for PROGRESS_BAR
impl Send for PROGRESS_BAR
impl Sync for PROGRESS_BAR
impl Unpin for PROGRESS_BAR
impl UnwindSafe for PROGRESS_BAR
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more