Skip to content

Commit b771bf1

Browse files
authored
add speed at the end (#23)
* add speed at the end Signed-off-by: kerthcet <kerthcet@gmail.com> * fix lint Signed-off-by: kerthcet <kerthcet@gmail.com> --------- Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent 699cf3f commit b771bf1

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/downloader/huggingface.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ impl Downloader for HuggingFaceDownloader {
117117
if cached_file_path.exists() {
118118
debug!("File {} found in cache, showing as complete", filename);
119119

120-
// Create progress bar and mark as instantly complete
121-
let mut file_progress = progress_manager_clone.create_file_progress(&filename);
120+
// Create progress bar for cached file (no speed display)
121+
let mut file_progress =
122+
progress_manager_clone.create_cached_file_progress(&filename);
122123
let file_size = cached_file_path.metadata().map(|m| m.len()).unwrap_or(0);
123124
file_progress.init(file_size);
124125
file_progress.update(file_size);

src/downloader/progress.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct DownloadProgressManager {
2222
multi_progress: Arc<MultiProgress>,
2323
total_size: Arc<AtomicU64>,
2424
style: ProgressStyle,
25+
cached_style: ProgressStyle,
2526
}
2627

2728
impl DownloadProgressManager {
@@ -30,18 +31,29 @@ impl DownloadProgressManager {
3031
let multi_progress = Arc::new(MultiProgress::new());
3132

3233
let template = format!(
33-
"{{msg:<{width}}} [{{elapsed_precise}}] {{bar:60.white}} {{bytes}}/{{total_bytes}}",
34+
"{{msg:<{width}}} [{{elapsed_precise}}] {{bar:60.white}} {{bytes}}/{{total_bytes}} {{bytes_per_sec}}",
3435
width = max_filename_len
3536
);
3637
let style = ProgressStyle::default_bar()
3738
.template(&template)
3839
.unwrap()
3940
.progress_chars("▇▆▅▄▃▂▁ ");
4041

42+
// Cached file style without speed
43+
let cached_template = format!(
44+
"{{msg:<{width}}} [{{elapsed_precise}}] {{bar:60.white}} {{bytes}}/{{total_bytes}}",
45+
width = max_filename_len
46+
);
47+
let cached_style = ProgressStyle::default_bar()
48+
.template(&cached_template)
49+
.unwrap()
50+
.progress_chars("▇▆▅▄▃▂▁ ");
51+
4152
Self {
4253
multi_progress,
4354
total_size: Arc::new(AtomicU64::new(0)),
4455
style,
56+
cached_style,
4557
}
4658
}
4759

@@ -57,6 +69,18 @@ impl DownloadProgressManager {
5769
}
5870
}
5971

72+
/// Create a new progress bar for a cached file (no speed display)
73+
pub fn create_cached_file_progress(&self, filename: &str) -> FileProgress {
74+
let pb = self.multi_progress.add(ProgressBar::hidden());
75+
pb.set_style(self.cached_style.clone());
76+
pb.set_message(filename.to_string());
77+
78+
FileProgress {
79+
pb,
80+
total_size: Arc::clone(&self.total_size),
81+
}
82+
}
83+
6084
/// Get the total accumulated download size
6185
pub fn total_downloaded_bytes(&self) -> u64 {
6286
self.total_size.load(Ordering::Relaxed)

0 commit comments

Comments
 (0)