From 1acbbb6d430d69720e0f9370d4649de92e510a31 Mon Sep 17 00:00:00 2001 From: Nidhal Messaoudi Date: Mon, 27 Feb 2023 21:17:45 +0100 Subject: [PATCH] Fixing the progress percentage --- src/verify.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/verify.rs b/src/verify.rs index cf319e4..68ba6ce 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -13,14 +13,15 @@ pub fn verify<'a>( progress: (usize, usize), verbose: bool, ) -> Result<(), &'a Exercise> { - let (mut num_done, total) = progress; + let (num_done, total) = progress; let bar = ProgressBar::new(total as u64); + let mut percentage = num_done as f32 / total as f32 * 100.0; bar.set_style(ProgressStyle::default_bar() .template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}") .progress_chars("#>-") ); bar.set_position(num_done as u64); - bar.set_message(format!("({:.1} %)", 0.)); + bar.set_message(format!("({:.1} %)", percentage)); for exercise in exercises { let compile_result = match exercise.mode { @@ -31,8 +32,7 @@ pub fn verify<'a>( if !compile_result.unwrap_or(false) { return Err(exercise); } - num_done += 1; - let percentage = num_done as f32 / total as f32 * 100.0; + percentage += 100.0 / total as f32; bar.inc(1); bar.set_message(format!("({:.1} %)", percentage)); }