Skip to content

Commit

Permalink
Refactor progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeder committed Nov 19, 2024
1 parent 0ba9e96 commit 747d0bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Leonid Beder <leonid@lbeder.com>"]
edition = "2021"
name = "slowkey"
version = "1.5.5"
version = "1.5.6"

[dependencies]
base64 = "0.21.7"
Expand Down
22 changes: 7 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,16 +538,12 @@ fn main() {

let mb = MultiProgress::new();

let pb = mb
.add(ProgressBar::new((iterations - offset) as u64))
.with_style(ProgressStyle::with_template("{bar:80.cyan/blue} {msg} ({eta})").unwrap())
.with_message(format!(
"{:>7}/{:<7} {}%",
offset,
iterations,
(offset * 100) as f32 / (iterations as f32),
));
let pb = mb.add(ProgressBar::new(iterations as u64)).with_style(
ProgressStyle::with_template("{bar:80.cyan/blue} {pos:>7}/{len:7} {percent}% ({eta})").unwrap(),
);

pb.set_position(offset as u64);
pb.reset_eta();
pb.enable_steady_tick(Duration::from_secs(1));

let mut cpb: Option<ProgressBar> = None;
Expand All @@ -561,6 +557,8 @@ fn main() {
);

if let Some(ref mut cpb) = &mut cpb {
cpb.set_position((offset / checkpointing_interval) as u64);
cpb.reset_eta();
cpb.enable_steady_tick(Duration::from_secs(1));
}
}
Expand Down Expand Up @@ -607,12 +605,6 @@ fn main() {
}

pb.inc(1);
pb.set_message(format!(
"{:>7}/{:<7} {}%",
current_iteration + 1,
iterations,
(((current_iteration + 1) * 100) as f32) / (iterations as f32)
));
},
);

Expand Down

0 comments on commit 747d0bc

Please sign in to comment.