Skip to content

Commit

Permalink
Merge pull request #1781 from solson/master
Browse files Browse the repository at this point in the history
Clear line properly for download progress
  • Loading branch information
kinnison authored Apr 21, 2019
2 parents 438bc19 + d52c15f commit c93feb0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/cli/download_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ impl DownloadTracker {
let speed = if len > 0 { sum / len as f64 } else { 0. };
let speed_h = HumanReadable(speed);

// First, move to the start of the current line and clear it.
let _ = self.term.as_mut().unwrap().carriage_return();
let _ = self.term.as_mut().unwrap().delete_line();

match self.content_len {
Some(content_len) => {
let content_len = content_len as f64;
Expand All @@ -156,11 +160,9 @@ impl DownloadTracker {
);
}
}
// delete_line() doesn't seem to clear the line properly.
// Instead, let's just print some whitespace to clear it.
let _ = write!(self.term.as_mut().unwrap(), " ");

// Since stdout is typically line-buffered and we don't print a newline, we manually flush.
let _ = self.term.as_mut().unwrap().flush();
let _ = self.term.as_mut().unwrap().carriage_return();
self.displayed_progress = true;
}
}
Expand Down

0 comments on commit c93feb0

Please sign in to comment.