work on progress bar :3

This commit is contained in:
2025-11-15 06:55:34 +00:00
parent 66b31db8d3
commit 69de65ee89

View File

@@ -14,7 +14,7 @@ use crate::{
static DOWNLOAD_CHAR: LazyLock<String> = LazyLock::new(|| "-".blue().bold().to_string());
static DONE_CHAR: LazyLock<String> = LazyLock::new(|| "#".green().bold().to_string());
const INFO_WIDTH: usize = 13;
static INPROGRESS_CHAR: LazyLock<String> = LazyLock::new(|| "-".purple().bold().to_string());
pub struct CopyPathsHandler;
@@ -86,6 +86,12 @@ impl SubstitutionStatusHandler {
.map(|&[_, expected, ..]| expected)
.sum()
}
fn get_running_copy(&self) -> u64 {
self.state_copy
.values()
.map(|&[_, expected, ..]| expected)
.sum()
}
fn get_unpacked(&self) -> u64 {
self.state_copy.values().map(|&[done, ..]| done).sum()
@@ -97,13 +103,17 @@ 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 expected = (((self.get_running() + self.get_running_copy()) as f64
/ (self.max_transfer + self.max_copy) as f64)
* 100.0) as u64;
let min = dl_percent.min(ex_percent);
let dl = dl_percent.saturating_sub(min);
let exp = expected.saturating_sub(min + dl);
let mbar = MultiBar([
BarSegment::Dynamic(&DONE_CHAR, min),
BarSegment::Dynamic(&DOWNLOAD_CHAR, dl),
BarSegment::Dynamic(" ", 100 - min - dl),
BarSegment::Dynamic(&INPROGRESS_CHAR, exp),
BarSegment::Dynamic(" ", 100 - min - dl - exp),
]);
let work_per_sec = if self.get_done() < self.max_transfer {
@@ -127,8 +137,8 @@ impl SubstitutionStatusHandler {
StyledString::new(Cow::Owned("Downloading".to_string()), Style::new()),
StyledString::new(
Cow::Owned(format!(
"{}/{} {}",
self.state_self[0], self.state_self[1], expected
"{}/{} {min} {dl} {expected}",
self.state_self[0], self.state_self[1]
)),
Style::new().purple(),
),