Skip to content

Commit

Permalink
Do not use boxcar windowing when displaying the final total of the speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Feb 17, 2022
1 parent c13f45d commit 5c0527e
Showing 1 changed file with 46 additions and 13 deletions.
59 changes: 46 additions & 13 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use unicode_segmentation::UnicodeSegmentation;
use crate::format::{
BinaryBytes, DecimalBytes, FormattedDuration, HumanBytes, HumanCount, HumanDuration,
};
use crate::state::ProgressState;
use crate::state::{ProgressState, Status};

/// Controls the rendering style of progress bars
#[derive(Clone)]
Expand Down Expand Up @@ -313,18 +313,51 @@ impl ProgressStyle {
HumanDuration(state.started.elapsed())
))
.unwrap(),
"per_sec" => buf
.write_fmt(format_args!("{:.4}/s", state.per_sec()))
.unwrap(),
"bytes_per_sec" => buf
.write_fmt(format_args!("{}/s", HumanBytes(state.per_sec() as u64)))
.unwrap(),
"binary_bytes_per_sec" => buf
.write_fmt(format_args!(
"{}/s",
BinaryBytes(state.per_sec() as u64)
))
.unwrap(),
"per_sec" => {
if matches!(&state.status, Status::InProgress) {
buf.write_fmt(format_args!("{:.4}/s", state.per_sec()))
.unwrap()
} else {
let bytes_per_sec =
state.len as f64 / state.started.elapsed().as_secs_f64();
buf.write_fmt(format_args!("{:.4}/s", bytes_per_sec as u64))
.unwrap()
}
}
"bytes_per_sec" => {
if matches!(&state.status, Status::InProgress) {
buf.write_fmt(format_args!(
"{}/s",
HumanBytes(state.per_sec() as u64)
))
.unwrap()
} else {
let bytes_per_sec =
state.len as f64 / state.started.elapsed().as_secs_f64();
buf.write_fmt(format_args!(
"{}/s",
HumanBytes(bytes_per_sec as u64)
))
.unwrap()
}
}
"binary_bytes_per_sec" => {
if matches!(&state.status, Status::InProgress) {
buf.write_fmt(format_args!(
"{}/s",
BinaryBytes(state.per_sec() as u64)
))
.unwrap()
} else {
let bytes_per_sec =
state.len as f64 / state.started.elapsed().as_secs_f64();
buf.write_fmt(format_args!(
"{}/s",
BinaryBytes(bytes_per_sec as u64)
))
.unwrap()
}
}
"eta_precise" => buf
.write_fmt(format_args!("{}", FormattedDuration(state.eta())))
.unwrap(),
Expand Down

0 comments on commit 5c0527e

Please sign in to comment.