feat: update progress

This commit is contained in:
2023-10-15 22:22:16 +08:00
parent 47a0625dcc
commit 7d0115541f
4 changed files with 4 additions and 4 deletions

28
src/util_progress.rs Normal file
View File

@@ -0,0 +1,28 @@
use indicatif::{ProgressBar, ProgressStyle};
const PB_PROGRESS: &str = "#-";
const PB_TEMPLATE: &str = "{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} {bytes_per_sec} ({eta})";
pub struct Progress {
progress_bar: ProgressBar,
}
impl Progress {
pub fn new(total: u64) -> Self {
let progress_bar = ProgressBar::new(total);
progress_bar.set_style(ProgressStyle::default_bar()
.template(PB_TEMPLATE).expect("SHOULD NOT FAIL")
.progress_chars(PB_PROGRESS)
);
Self { progress_bar }
}
pub fn position(&self, position: u64) {
self.progress_bar.set_position(position)
}
pub fn finish(&self) {
self.progress_bar.finish_and_clear()
}
}