Skip to content

Commit

Permalink
feat: finish_print implemetation including example
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Oct 19, 2016
1 parent 8c25c80 commit d41952d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 1 addition & 3 deletions examples/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ fn main() {
thread::sleep(Duration::from_millis(100));
pb.tick();
}
pb.message("Completed! ");
pb.tick();
pb.finish();
pb.finish_print(&format!("Bar {} completed !", i));
});
}

Expand Down
21 changes: 20 additions & 1 deletion src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,27 @@ impl<T: Write> ProgressBar<T> {
self.is_finish = true;
}

/// Call finish and write string 's'

/// Call finish and write string 's' that will replace the progress bar.
pub fn finish_print(&mut self, s: &str) {
self.finish();
let width = if let Some(w) = self.width {
w
} else if let Some((Width(w), _)) = terminal_size() {
w as usize
} else {
80
};
let mut out = format!("{}", s);
if s.len() < width {
out += repeat!(" ", width-s.len());
};
printfl!(self.handle, "\r{}", out);
}


/// Call finish and write string 's' below the progress bar.
pub fn finish_println(&mut self, s: &str) {
self.finish();
printfl!(self.handle, "\n{}", s)
}
Expand Down

0 comments on commit d41952d

Please sign in to comment.