work on bar display and stuff

This commit is contained in:
2025-11-14 21:21:14 +00:00
parent b9c63c08b6
commit e958b461f6
3 changed files with 383 additions and 171 deletions

View File

@@ -1,10 +1,11 @@
use std::{collections::HashMap, sync::LazyLock, time::Instant};
use std::{borrow::Cow, collections::HashMap, sync::LazyLock, time::Instant};
use indicatif::{HumanBytes, ProgressBar};
use owo_colors::OwoColorize;
use owo_colors::{OwoColorize, Style};
use crate::{
action::{Action, ActionType, BuildStepId, ResultFields, StartFields},
download_display::{StyledString, style_bar},
estimator::Estimator,
handlers::{Handler, fetch::FetchHandler},
multibar::{BarSegment, MultiBar},
@@ -31,6 +32,8 @@ impl Handler for CopyPathsHandler {
} => {
state.println(format!("CopyPaths start"))?;
let progress = state.add_pb(ProgressBar::new(1));
progress.set_style(indicatif::ProgressStyle::with_template("{msg}").unwrap());
state.plug(SubstitutionStatusHandler::new(
id,
state.term_width,
@@ -84,7 +87,34 @@ impl SubstitutionStatusHandler {
self.state_copy.values().map(|&[done, ..]| done).sum()
}
fn draw_bar(&mut self, width: u16) {}
fn draw_bar(&mut self, width: u16) {
if self.max_transfer == 0 || self.max_copy == 0 {
return;
}
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 min = dl_percent.min(ex_percent);
let dl = dl_percent.saturating_sub(min);
let mbar = MultiBar([
BarSegment::Dynamic(&DONE_CHAR, min),
BarSegment::Dynamic(&DOWNLOAD_CHAR, dl),
BarSegment::Dynamic(" ", 100 - min - dl),
]);
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])),
Style::new().purple(),
),
StyledString::new(Cow::Owned(format!("awa")), Style::new().yellow()),
self.get_done() as usize,
self.get_unpacked() as usize,
mbar,
width,
);
self.progress.set_message(msg);
self.progress.tick();
}
}
impl Handler for SubstitutionStatusHandler {