Struct pbr::ProgressBar [] [src]

pub struct ProgressBar {
    pub is_finish: 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
}

Fields

is_finish: bool show_bar: bool show_speed: bool show_percent: bool show_counter: bool show_time_left: bool show_tick: bool show_message: bool

Methods

impl ProgressBar
[src]

fn new(total: u64) -> ProgressBar

Create a new ProgressBar with default configuration.

Examples

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

fn set_units(&mut self, u: Units)

Set units, default is simple numbers

Examples

use pbr::{ProgressBar, Units};

let n_bytes = 100;
let mut pb = ProgressBar::new(n_bytes);
pb.set_units(Units::Bytes);

fn format(&mut self, fmt: &str)

Set custom format to the drawing bar, default is [=>-]

Examples

let mut pb = ProgressBar::new(...);
pb.format("[=>_]");

fn message(&mut self, message: &str)

Set message to display in the prefix, call with "" to stop printing a message.

Examples

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

fn tick_format(&mut self, tick_fmt: &str)

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

Examples

let mut pb = ProgressBar::new(...);
pb.tick_format("▀▐▄▌")

fn tick(&mut self)

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.

Examples

let mut pb = ProgressBar::new(...);
pb.inc();
for _ in ... {
   ...do something
   pb.tick();
}
pb.finish();

fn add(&mut self, i: u64) -> u64

Add to current value

Examples

use pbr::ProgressBar;

let mut pb = ProgressBar::new(10);
pb.add(5);
pb.finish();

fn inc(&mut self) -> u64

Increment current value

fn finish(&mut self)

Calling finish manually will set current to total and draw the last time

fn finish_print(&mut self, s: &str)

Call finish and write string 's'

Trait Implementations

impl Debug for ProgressBar
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Write for ProgressBar
[src]

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this object, returning how many bytes were written. Read more

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

fn write_all(&mut self, buf: &[u8]) -> Result<()Error>
1.0.0

Attempts to write an entire buffer into this write. Read more

fn write_fmt(&mut self, fmt: Arguments) -> Result<()Error>
1.0.0

Writes a formatted string into this writer, returning any error encountered. Read more

fn by_ref(&mut self) -> &mut Self
1.0.0

Creates a "by reference" adaptor for this instance of Write. Read more