diff --git a/src/main.rs b/src/main.rs index 189ecb069..bde76b67c 100755 --- a/src/main.rs +++ b/src/main.rs @@ -382,13 +382,13 @@ enum WatchStatus { Unfinished, } -fn watch(exercises: &[Exercise]) -> notify::Result { - /* Clears the terminal with an ANSI escape code. - Works in UNIX and newer Windows terminals. */ - fn clear_screen() { - println!("\x1Bc"); - } +// Clears the terminal with an ANSI escape code. +// Works in UNIX and newer Windows terminals. +pub fn clear_screen() { + println!("\x1Bc"); +} +fn watch(exercises: &[Exercise]) -> notify::Result { let (tx, rx) = channel(); let should_quit = Arc::new(AtomicBool::new(false)); @@ -419,7 +419,6 @@ fn watch(exercises: &[Exercise]) -> notify::Result { .filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)), ); let num_done = exercises.iter().filter(|e| e.looks_done()).count(); - clear_screen(); match verify(pending_exercises, (num_done, exercises.len())) { Ok(_) => return Ok(WatchStatus::Finished), Err(exercise) => { diff --git a/src/verify.rs b/src/verify.rs index b9e1aba20..5dce34415 100755 --- a/src/verify.rs +++ b/src/verify.rs @@ -1,4 +1,7 @@ -use crate::exercise::{Exercise, Mode, State}; +use crate::{ + clear_screen, + exercise::{Exercise, Mode, State}, +}; use console::style; use indicatif::{ProgressBar, ProgressStyle}; use std::env; @@ -12,15 +15,16 @@ pub fn verify<'a>( exercises: impl IntoIterator, progress: (usize, usize), ) -> Result<(), &'a Exercise> { - let (num_done, total) = progress; - let bar = ProgressBar::new(total as u64); - bar.set_style( - ProgressStyle::default_bar() - .template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}\n") - .progress_chars("#>-"), - ); - bar.set_position(num_done as u64); + let (mut num_done, total) = progress; for exercise in exercises { + clear_screen(); + let bar = ProgressBar::new(total as u64); + bar.set_style( + ProgressStyle::default_bar() + .template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}\n") + .progress_chars("#>-"), + ); + bar.set_position(num_done as u64); let compile_result = match exercise.mode { Mode::Compile => compile_and_run_interactively(exercise), Mode::Test => compile_and_test_interactively(exercise), @@ -30,7 +34,7 @@ pub fn verify<'a>( } let percentage = num_done as f32 / total as f32 * 100.0; bar.set_message(format!("({percentage:.1} %)")); - bar.inc(1); + num_done += 1; } Ok(()) }