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

Clear line properly for download progress #1781

Merged
merged 1 commit into from
Apr 21, 2019
Merged
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
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