Struct progress_string::Bar
[−]
[src]
pub struct Bar { pub current_partial: usize, pub total: usize, // some fields omitted }
Represents a progress bar, this can be used to get your progress string
Fields
current_partial: usize
total: usize
Methods
impl Bar
[src]
impl Bar
[src]
fn update(&mut self, to_add: usize)
[src]
Update the current_partial value by adding the to_add parameter
Examples
let mut bar = Bar::default(); bar.update(10); assert_eq!(bar.current_partial, 110);
fn replace(&mut self, new_progress: usize)
[src]
Update the cureent partial by replacing the current value
Examples
let mut bar = Bar::default(); bar.replace(10); assert_eq!(bar.current_partial, 10);
impl Bar
[src]
fn to_string(&self) -> String
[src]
Get the string representation of the progress bar
This stiring will include brackets ([]) around the
empty/full characters, the width is determined by
the width property.
If bar.include_percent == true
the resulting string will include a space and the
percent with 2 decimal palces followed by %.
Examples
let mut with_percent = BarBuilder::new().include_percent() .get_bar(); with_percent.update(50); println!("{}", with_percent.to_string()); //prints [█████████████████████████ ] 50.00% let mut no_percent = BarBuilder::new().get_bar(); no_percent.update(50); //prints [█████████████████████████ ]
impl Bar
[src]
fn get_width(&self) -> usize
[src]
Get the current width of characters in the bar, this includes the brackets, spaces and percent if set
Examples
let bar = Bar::default(); println!("{}", bar.get_width()); //prints 52 let mut with_percent = BarBuilder;;new().include_precent(); println!("{}", bar.get_width()); //prints 58 with_percent.update(10); println!("{}", bar.get_width()); //prints 59 with_percent.replace(100); println!("{}", bar.get_width()); //prints 60
fn get_last_width(&self) -> usize
[src]
Similar to get_width
but gets the value
before the last update
or replace
call
this is useful for when you are trying to clear
the terminal