Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add writeln to print without breaking pbr #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<T: Write> ProgressBar<T> {
self.add(1)
}

fn draw(&mut self) {
pub fn draw(&mut self) {
let now = SteadyTime::now();
if let Some(mrr) = self.max_refresh_rate {
if now - self.last_refresh_time < mrr {
Expand Down Expand Up @@ -396,6 +396,13 @@ impl<T: Write> ProgressBar<T> {
self.last_refresh_time = SteadyTime::now();
}

/// Print a line above the progress bar
pub fn writeln(&mut self, s: &str) {
printfl!(self.handle, "\r\x1B[2K{}\n", s);
self.draw();
}


// finish_draw ensure that the progress bar is reached to its end, and do the
// last drawing if needed.
fn finish_draw(&mut self) {
Expand Down Expand Up @@ -455,7 +462,7 @@ impl<T: Write> ProgressBar<T> {
}

/// Get terminal width, from configuration, terminal size, or default(80)
fn width(&mut self) -> usize {
pub fn width(&mut self) -> usize {
if let Some(w) = self.width {
w
} else if let Some((Width(w), _)) = terminal_size() {
Expand Down