Skip to content

Commit

Permalink
feat: add progress indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Oct 19, 2024
1 parent c8ec10a commit 1a5f45c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"docus",
"docyou",
"hexdigit",
"indicatif",
"lightningcss",
"mockall",
"registerables",
Expand Down
60 changes: 60 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
chrono = { version = "0.4.38", features = ["serde"] }
futures = "0.3.31"
indicatif = "0.17.8"
open = "5.3.0"
oxc = "0.31.0"
regex = "1.11.0"
Expand Down
17 changes: 13 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use futures::future::join_all;
use indicatif::{ProgressBar, ProgressStyle};
use open;
use serde_json::json;
use std::fs::File;
Expand Down Expand Up @@ -141,11 +142,17 @@ async fn main() {
let history_len = history.len();
let semaphore = Arc::new(Semaphore::new(24));

for (index, (commit_hash, date)) in history.iter().enumerate() {
let percentage =
((index + 1) as f64 / history_len as f64 * 100.0).round() as i32;
let progress_bar = ProgressBar::new(history_len as u64);

let progress_style = ProgressStyle::default_bar()
.template("{bar:40.cyan/blue} {pos}/{len} ({percent}%)")
.expect("Failed to create progress bar template")
.progress_chars("▇▇ ");
progress_bar.set_style(progress_style);

for (_index, (commit_hash, date)) in history.iter().enumerate() {
progress_bar.inc(1);

print!("\rProcessed {:.2}% of commits", percentage);
io::stdout().flush().unwrap();

let files_list =
Expand Down Expand Up @@ -207,6 +214,8 @@ async fn main() {
.expect("Failed to write to temp file");
}

progress_bar.finish_with_message("All commits processed!");

writer.flush().expect("Failed to flush writer");

if fs::metadata(TODOCTOR_DIR).await.is_ok() {
Expand Down

0 comments on commit 1a5f45c

Please sign in to comment.