Print download progress to stderr instead

This commit is contained in:
Ching Pei Yang 2023-12-01 19:48:36 +01:00
parent f2f58b062d
commit 6f3588186c
No known key found for this signature in database
GPG Key ID: 062FBBCE1D0C5DD9

View File

@ -433,21 +433,21 @@ impl<R: Read> Read for ProgressReporter<R> {
self.read += size;
if let Some(total) = self.total {
print!(
eprint!(
"\u{001b}[2K\u{001b}[G[{:.1} / {:.1} MB]",
self.read as f32 / 1_000_000.0,
total as f32 / 1_000_000.0,
);
} else {
print!(
eprint!(
"\u{001b}[2K\u{001b}[G[{:.1} MB]",
self.read as f32 / 1_000_000.0,
);
}
std::io::stdout().flush()?;
std::io::stderr().flush()?;
if self.total.is_some_and(|total| self.read >= total) {
println!();
eprintln!();
}
Ok(size)