pub struct ProgressBar<T> where
T: Write, {
pub total: u64,
pub is_finish: bool,
pub is_multibar: bool,
pub show_bar: bool,
pub show_speed: bool,
pub show_percent: bool,
pub show_counter: bool,
pub show_time_left: bool,
pub show_tick: bool,
pub show_message: bool,
// some fields omitted
}
Create a new ProgressBar with default configuration.
use std::thread;
use pbr::{ProgressBar, Units};
let count = 1000;
let mut pb = ProgressBar::new(count);
pb.set_units(Units::Bytes);
for _ in 0..count {
pb.inc();
thread::sleep_ms(100);
}
Create a new ProgressBar with default configuration but
pass an arbitrary writer.
use std::thread;
use std::io::stderr;
use pbr::{ProgressBar, Units};
let count = 1000;
let mut pb = ProgressBar::on(stderr(), count);
pb.set_units(Units::Bytes);
for _ in 0..count {
pb.inc();
thread::sleep_ms(100);
}
Set units, default is simple numbers
use pbr::{ProgressBar, Units};
let n_bytes = 100;
let mut pb = ProgressBar::new(n_bytes);
pb.set_units(Units::Bytes);
Set custom format to the drawing bar, default is [=>-]
let mut pb = ProgressBar::new(...);
pb.format("[=>_]");
Set message to display in the prefix, call with "" to stop printing a message.
All newlines are replaced with spaces.
let mut pb = ProgressBar::new(20);
for x in 0..20 {
match x {
0 => pb.message("Doing 1st Quarter"),
5 => pb.message("Doing 2nd Quarter"),
10 => pb.message("Doing 3rd Quarter"),
15 => pb.message("Doing 4th Quarter"),
}
pb.inc().
}
Set tick format for the progressBar, default is \|/-
Format is not limited to 4 characters, any string can
be used as a tick format (the tick will successively
take the value of each char but won't loop backwards).
let mut pb = ProgressBar::new(...);
pb.tick_format("▀▐▄▌")
Set width, or None
for default.
let mut pb = ProgressBar::new(...);
pb.set_width(Some(80));
Set max refresh rate, above which the progress bar will not redraw, or None
for none.
let mut pb = ProgressBar::new(...);
pb.set_max_refresh_rate(Some(Duration::from_millis(100)));
Update progress bar even though no progress are made
Useful to see if a program is bricked or just
not doing any progress.
tick is not needed with add or inc
as performed operation take place
in draw function.
let mut pb = ProgressBar::new(...);
pb.inc();
for _ in ... {
...do something
pb.tick();
}
pb.finish();
Add to current value
use pbr::ProgressBar;
let mut pb = ProgressBar::new(10);
pb.add(5);
pb.finish();
Manually set the current value of the bar
use pbr::ProgressBar;
let mut pb = ProgressBar::new(10);
pb.set(8);
pb.finish();
Calling finish manually will set current to total and draw
the last time
Call finish and write string s
that will replace the progress bar.
Call finish and write string s
below the progress bar.
If the ProgressBar is part of MultiBar instance, you should use
finish_print
to print message.
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Attempts to write an entire buffer into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a "by reference" adaptor for this instance of Write
. Read more
Implement the progress reporter trait for a progress bar,
to make it usable for frame processing reporting.
Increase the progress counter. Return false
to abort processing.
Mark the progress as done.
type Error = !
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Sets value
as a parameter of self
.