Merge pull request #1404 from nidhalmessaoudi/master

Always showing correct progress percentages.
This commit is contained in:
liv 2023-03-10 11:51:08 +01:00 committed by GitHub
commit c8273e06c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,14 +13,15 @@ pub fn verify<'a>(
progress: (usize, usize), progress: (usize, usize),
verbose: bool, verbose: bool,
) -> Result<(), &'a Exercise> { ) -> Result<(), &'a Exercise> {
let (mut num_done, total) = progress; let (num_done, total) = progress;
let bar = ProgressBar::new(total as u64); 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() bar.set_style(ProgressStyle::default_bar()
.template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}") .template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}")
.progress_chars("#>-") .progress_chars("#>-")
); );
bar.set_position(num_done as u64); bar.set_position(num_done as u64);
bar.set_message(format!("({:.1} %)", 0.)); bar.set_message(format!("({:.1} %)", percentage));
for exercise in exercises { for exercise in exercises {
let compile_result = match exercise.mode { let compile_result = match exercise.mode {
@ -31,8 +32,7 @@ pub fn verify<'a>(
if !compile_result.unwrap_or(false) { if !compile_result.unwrap_or(false) {
return Err(exercise); return Err(exercise);
} }
num_done += 1; percentage += 100.0 / total as f32;
let percentage = num_done as f32 / total as f32 * 100.0;
bar.inc(1); bar.inc(1);
bar.set_message(format!("({:.1} %)", percentage)); bar.set_message(format!("({:.1} %)", percentage));
} }