start standardising bar display
This commit is contained in:
100
src/download_display.rs
Normal file
100
src/download_display.rs
Normal file
@@ -0,0 +1,100 @@
|
||||
pub fn format(&self, width: u16) {
|
||||
let name = pad_string(&name, (width / 4) as usize);
|
||||
let status = format!("Download {} |", name.purple().bold());
|
||||
let status_len = (width / 4) as usize + 10;
|
||||
|
||||
if self.download_expected == 0 || self.extract_expected == 0 {
|
||||
self.bar.set_message(format!("{status}"));
|
||||
self.bar.tick();
|
||||
return;
|
||||
}
|
||||
|
||||
let total_expected = self.download_expected + self.extract_expected;
|
||||
let total_done = self.download_done + self.extract_done;
|
||||
|
||||
let dl_percent = ((self.download_done as f64 / self.download_expected as f64) * 100.0) as u64;
|
||||
let ex_percent = ((self.extract_done as f64 / self.extract_expected as f64) * 100.0) as u64;
|
||||
|
||||
let download_per_sec =
|
||||
HumanBytes(self.download_estimator.steps_per_second(Instant::now()) as u64).to_string();
|
||||
let extract_per_sec =
|
||||
HumanBytes(self.extract_estimator.steps_per_second(Instant::now()) as u64).to_string();
|
||||
let download_done_human = HumanBytes(self.download_done).to_string();
|
||||
let download_done_human = pad_string(&download_done_human, INFO_WIDTH)
|
||||
.blue()
|
||||
.bold()
|
||||
.to_string();
|
||||
let extract_done_human = HumanBytes(self.extract_done).to_string();
|
||||
let extract_done_human = pad_string(&extract_done_human, INFO_WIDTH)
|
||||
.green()
|
||||
.bold()
|
||||
.to_string();
|
||||
let download_per_sec = pad_string(&format!("{download_per_sec}/s"), INFO_WIDTH)
|
||||
.blue()
|
||||
.bold()
|
||||
.to_string();
|
||||
let extract_per_sec = pad_string(&format!("{extract_per_sec}/s"), INFO_WIDTH)
|
||||
.green()
|
||||
.bold()
|
||||
.to_string();
|
||||
let work_per_sec = if self.download_done < self.download_expected {
|
||||
download_per_sec
|
||||
} else {
|
||||
extract_per_sec
|
||||
};
|
||||
|
||||
let display = format!("{work_per_sec} | {download_done_human} | {extract_done_human} ");
|
||||
let display_length = (INFO_WIDTH * 3) + 9;
|
||||
|
||||
// + 6 to account for final format
|
||||
let total_length = status_len + display_length + 4;
|
||||
|
||||
let min = dl_percent.min(ex_percent);
|
||||
let dl = dl_percent.saturating_sub(min);
|
||||
let len = total_length as u16;
|
||||
// if width <= len {
|
||||
// self.bar.set_message(format!(
|
||||
// "{}: {}/{}",
|
||||
// name,
|
||||
// total_done,
|
||||
// if total_expected == 0 {
|
||||
// "-".to_string()
|
||||
// } else {
|
||||
// total_expected.to_string()
|
||||
// }
|
||||
// ));
|
||||
// self.bar.tick();
|
||||
// return;
|
||||
// }
|
||||
let msg = match width {
|
||||
0..60 => {
|
||||
format!(
|
||||
"{}: {}/{}",
|
||||
name,
|
||||
total_done,
|
||||
if total_expected == 0 {
|
||||
"-".to_string()
|
||||
} else {
|
||||
total_expected.to_string()
|
||||
}
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
let bar = MultiBar([
|
||||
BarSegment::Dynamic(&DONE_CHAR, min),
|
||||
BarSegment::Dynamic(&DOWNLOAD_CHAR, dl),
|
||||
BarSegment::Dynamic(" ", 100 - min - dl),
|
||||
])
|
||||
.scale((width.saturating_sub(total_length as u16)) as u64);
|
||||
let bar = if width > display_length as u16 + status_len as u16 {
|
||||
format!("[{}]", bar)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
format!("{status} {display} {bar}",)
|
||||
}
|
||||
};
|
||||
self.bar.set_message(msg);
|
||||
self.bar.tick();
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use crate::state::State;
|
||||
|
||||
pub mod action;
|
||||
pub mod action_raw;
|
||||
pub mod download_display;
|
||||
pub mod download_pb;
|
||||
pub mod estimator;
|
||||
pub mod handlers;
|
||||
|
||||
Reference in New Issue
Block a user