Struct progress_bar::pb::ProgressBar
source · pub struct ProgressBar { /* private fields */ }
Implementations§
source§impl ProgressBar
impl ProgressBar
sourcepub fn new(max: usize) -> Self
pub fn new(max: usize) -> Self
Creates a progress bar with the total number of actions.
You will need to call inc method when an action is completed and the bar progress will be incremented by 1.
Don’t print things with print macro while the bar is running; use the print_info method instead.
Example
use progress_bar::progress_bar::ProgressBar;
use progress_bar::color::{Color, Style};
use std::{thread, time};
// if you have 81 pages to load
let mut progress_bar = ProgressBar::new(81);
progress_bar.set_action("Loading", Color::Blue, Style::Bold);
for i in 0..81 {
// load page
thread::sleep(time::Duration::from_millis(50));
// log the result
if i == 14 {
progress_bar.print_info("Failed", "https://zefzef.zef", Color::Red, Style::Blink);
} else {
progress_bar.print_info("Success", "https://example.com", Color::Red, Style::Blink);
}
// increase the progress by 1
progress_bar.inc();
}
progress_bar.print_final_info("Loading", "Load complete", Color::LightGreen, Style::Bold);
// Or, to leave the progress bar at 100%:
// progress_bar.finalize();
sourcepub fn new_with_eta(max: usize) -> Self
pub fn new_with_eta(max: usize) -> Self
Same as ProgressBar::new but enabled ETA display.
sourcepub fn set_width(&mut self, w: usize)
pub fn set_width(&mut self, w: usize)
Set the width of the progress bar in caracters in console (default: 50)
pub fn set_progression(&mut self, p: usize)
👎Deprecated: Use set_progress instead
sourcepub fn set_progress(&mut self, p: usize)
pub fn set_progress(&mut self, p: usize)
Set the progres
sourcepub fn enable_eta(&mut self)
pub fn enable_eta(&mut self)
Resets progress and enables ETA
sourcepub fn disable_eta(&mut self)
pub fn disable_eta(&mut self)
Disables ETA
sourcepub fn set_action(&mut self, a: &str, c: Color, s: Style)
pub fn set_action(&mut self, a: &str, c: Color, s: Style)
Set the global action displayed before the progress bar.
sourcepub fn print_final_info(
&mut self,
info_name: &str,
text: &str,
info_color: Color,
info_style: Style
)
pub fn print_final_info( &mut self, info_name: &str, text: &str, info_color: Color, info_style: Style )
Log something, without display update
Auto Trait Implementations§
impl RefUnwindSafe for ProgressBar
impl Send for ProgressBar
impl Sync for ProgressBar
impl Unpin for ProgressBar
impl UnwindSafe for ProgressBar
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
Mutably borrows from an owned value. Read more