work on bars more

This commit is contained in:
2025-11-14 22:10:15 +00:00
parent 22550dec98
commit 66b31db8d3
2 changed files with 35 additions and 4 deletions

View File

@@ -5,7 +5,7 @@ use owo_colors::{OwoColorize, Style};
use crate::{
action::{Action, ActionType, BuildStepId, ResultFields, StartFields},
download_display::{StyledString, style_bar},
download_display::{DOWNLOAD_STYLE, EXTRACT_STYLE, StyledString, style_bar},
estimator::Estimator,
handlers::{Handler, fetch::FetchHandler},
multibar::{BarSegment, MultiBar},
@@ -50,6 +50,8 @@ impl Handler for CopyPathsHandler {
pub struct SubstitutionStatusHandler {
id: BuildStepId,
progress: ProgressBar,
download_estimator: Estimator,
extract_estimator: Estimator,
state_copy: HashMap<BuildStepId, [u64; 2]>,
state_transfer: HashMap<BuildStepId, [u64; 2]>,
state_self: [u64; 2],
@@ -62,6 +64,8 @@ impl SubstitutionStatusHandler {
let mut new = Self {
id: *id,
progress,
download_estimator: Estimator::new(Instant::now()),
extract_estimator: Estimator::new(Instant::now()),
state_copy: HashMap::new(),
state_transfer: HashMap::new(),
state_self: [0, 0],
@@ -93,6 +97,7 @@ impl SubstitutionStatusHandler {
}
let dl_percent = ((self.get_done() as f64 / self.max_transfer as f64) * 100.0) as u64;
let ex_percent = ((self.get_unpacked() as f64 / self.max_copy as f64) * 100.0) as u64;
let expected = ((self.get_running() as f64 / self.get_done() as f64) * 100.0) as u64;
let min = dl_percent.min(ex_percent);
let dl = dl_percent.saturating_sub(min);
let mbar = MultiBar([
@@ -100,13 +105,34 @@ impl SubstitutionStatusHandler {
BarSegment::Dynamic(&DOWNLOAD_CHAR, dl),
BarSegment::Dynamic(" ", 100 - min - dl),
]);
let work_per_sec = if self.get_done() < self.max_transfer {
StyledString::new(
Cow::Owned(format!(
"{}",
HumanBytes(self.download_estimator.steps_per_second(Instant::now()) as u64)
)),
DOWNLOAD_STYLE,
)
} else {
StyledString::new(
Cow::Owned(format!(
"{}",
HumanBytes(self.extract_estimator.steps_per_second(Instant::now()) as u64)
)),
EXTRACT_STYLE,
)
};
let msg = style_bar(
StyledString::new(Cow::Owned("Downloading".to_string()), Style::new()),
StyledString::new(
Cow::Owned(format!("{}/{}", self.state_self[0], self.state_self[1])),
Cow::Owned(format!(
"{}/{} {}",
self.state_self[0], self.state_self[1], expected
)),
Style::new().purple(),
),
StyledString::new(Cow::Owned(format!("awa")), Style::new().yellow()),
work_per_sec,
self.get_done() as usize,
self.get_unpacked() as usize,
mbar,
@@ -176,11 +202,16 @@ impl Handler for SubstitutionStatusHandler {
}
if let Some(copy) = self.state_copy.get_mut(id) {
*copy = [*done, *expected];
self.extract_estimator
.record(self.get_unpacked(), Instant::now());
self.draw_bar(state.term_width);
}
if let Some(transfer) = self.state_transfer.get_mut(id) {
*transfer = [*done, *expected];
self.download_estimator
.record(self.get_done(), Instant::now());
self.draw_bar(state.term_width);
}
Ok(true)