Skip to content

Commit e089354

Browse files
authored
feat(pb): format index with fixed width (#578)
1 parent ce0cb9f commit e089354

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/pb.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ impl OmaMultiProgressBar {
264264
let pb = self
265265
.mb
266266
.insert(index + 1, ProgressBar::new_spinner().with_style(sty));
267-
pb.set_message(format!("({}/{total}) {msg}", index + 1));
267+
let total_width = total_width(total);
268+
pb.set_message(format!("({:>total_width$}/{total}) {msg}", index + 1));
268269
pb.enable_steady_tick(inv);
269270
self.pb_map.insert(index + 1, pb);
270271
}
@@ -278,7 +279,8 @@ impl OmaMultiProgressBar {
278279
let pb = self
279280
.mb
280281
.insert(index + 1, ProgressBar::new(size).with_style(sty));
281-
pb.set_message(format!("({}/{total}) {msg}", index + 1));
282+
let total_width = total_width(total);
283+
pb.set_message(format!("({:>total_width$}/{total}) {msg}", index + 1));
282284
self.pb_map.insert(index + 1, pb);
283285
}
284286
Event::ProgressInc { index, size } => {
@@ -378,6 +380,11 @@ impl OmaMultiProgressBar {
378380
}
379381
}
380382

383+
#[inline]
384+
fn total_width(total: usize) -> usize {
385+
total.to_string().len()
386+
}
387+
381388
fn osc94(is_refresh: bool, download_only: bool, pos: u64, gpb: &ProgressBar) {
382389
if let Some(len) = gpb.length()
383390
&& !is_refresh

0 commit comments

Comments
 (0)