From c0b8af2c42c5e116cb9f91b42da4dd5d92baeaed Mon Sep 17 00:00:00 2001 From: mo8it Date: Sat, 26 Aug 2023 23:35:07 +0200 Subject: [PATCH] Fix indicatif --- src/run.rs | 3 ++- src/verify.rs | 35 +++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/run.rs b/src/run.rs index 1e2e56c..e0ada4c 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,4 +1,5 @@ use std::process::Command; +use std::time::Duration; use crate::exercise::{Exercise, Mode}; use crate::verify::test; @@ -36,7 +37,7 @@ pub fn reset(exercise: &Exercise) -> Result<(), ()> { fn compile_and_run(exercise: &Exercise) -> Result<(), ()> { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Compiling {exercise}...")); - progress_bar.enable_steady_tick(100); + progress_bar.enable_steady_tick(Duration::from_millis(100)); let compilation_result = exercise.compile(); let compilation = match compilation_result { diff --git a/src/verify.rs b/src/verify.rs index f3f3b56..01dd87f 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -1,7 +1,7 @@ use crate::exercise::{CompiledExercise, Exercise, Mode, State}; use console::style; use indicatif::{ProgressBar, ProgressStyle}; -use std::env; +use std::{env, time::Duration}; // Verify that the provided container of Exercise objects // can be compiled and run without any failures. @@ -17,9 +17,11 @@ pub fn verify<'a>( 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_style( + ProgressStyle::default_bar() + .template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}") + .expect("Progressbar template should be valid!") + .progress_chars("#>-"), ); bar.set_position(num_done as u64); bar.set_message(format!("({:.1} %)", percentage)); @@ -55,7 +57,7 @@ pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> { fn compile_only(exercise: &Exercise, success_hints: bool) -> Result { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Compiling {exercise}...")); - progress_bar.enable_steady_tick(100); + progress_bar.enable_steady_tick(Duration::from_millis(100)); let _ = compile(exercise, &progress_bar)?; progress_bar.finish_and_clear(); @@ -67,7 +69,7 @@ fn compile_only(exercise: &Exercise, success_hints: bool) -> Result { fn compile_and_run_interactively(exercise: &Exercise, success_hints: bool) -> Result { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Compiling {exercise}...")); - progress_bar.enable_steady_tick(100); + progress_bar.enable_steady_tick(Duration::from_millis(100)); let compilation = compile(exercise, &progress_bar)?; @@ -85,15 +87,24 @@ fn compile_and_run_interactively(exercise: &Exercise, success_hints: bool) -> Re } }; - Ok(prompt_for_completion(exercise, Some(output.stdout), success_hints)) + Ok(prompt_for_completion( + exercise, + Some(output.stdout), + success_hints, + )) } // Compile the given Exercise as a test harness and display // the output if verbose is set to true -fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool, success_hints: bool) -> Result { +fn compile_and_test( + exercise: &Exercise, + run_mode: RunMode, + verbose: bool, + success_hints: bool, +) -> Result { let progress_bar = ProgressBar::new_spinner(); progress_bar.set_message(format!("Testing {exercise}...")); - progress_bar.enable_steady_tick(100); + progress_bar.enable_steady_tick(Duration::from_millis(100)); let compilation = compile(exercise, &progress_bar)?; let result = compilation.run(); @@ -143,7 +154,11 @@ fn compile<'a, 'b>( } } -fn prompt_for_completion(exercise: &Exercise, prompt_output: Option, success_hints: bool) -> bool { +fn prompt_for_completion( + exercise: &Exercise, + prompt_output: Option, + success_hints: bool, +) -> bool { let context = match exercise.state() { State::Done => return true, State::Pending(context) => context,