diff options
| author | mo8it <mo8it@proton.me> | 2024-04-12 18:57:04 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-04-12 18:57:04 +0200 |
| commit | d5a6dee1b329f68d00bee61c6b6c7a0adbf8bab5 (patch) | |
| tree | d0f01f6862ad900710d70a168d0a2d9f539b85ae /src/run.rs | |
| parent | a534de0312ff47d5e87b3bf60d508bdaafb98fbc (diff) | |
Handle the case when all exercises are done
Diffstat (limited to 'src/run.rs')
| -rw-r--r-- | src/run.rs | 24 |
1 files changed, 10 insertions, 14 deletions
@@ -1,6 +1,6 @@ use anyhow::{bail, Result}; use crossterm::style::Stylize; -use std::io::{stdout, Write}; +use std::io::{self, Write}; use crate::app_state::{AppState, ExercisesProgress}; @@ -8,28 +8,24 @@ pub fn run(app_state: &mut AppState) -> Result<()> { let exercise = app_state.current_exercise(); let output = exercise.run()?; - { - let mut stdout = stdout().lock(); - stdout.write_all(&output.stdout)?; - stdout.write_all(&output.stderr)?; - stdout.flush()?; - } + let mut stdout = io::stdout().lock(); + stdout.write_all(&output.stdout)?; + stdout.write_all(b"\n")?; + stdout.write_all(&output.stderr)?; + stdout.flush()?; if !output.status.success() { bail!("Ran {exercise} with errors"); } - println!( + stdout.write_fmt(format_args!( "{}{}", "✓ Successfully ran ".green(), exercise.path.to_string_lossy().green(), - ); + ))?; - match app_state.done_current_exercise()? { - ExercisesProgress::AllDone => println!( - "🎉 Congratulations! You have done all the exercises! -🔚 There are no more exercises to do next!" - ), + match app_state.done_current_exercise(&mut stdout)? { + ExercisesProgress::AllDone => (), ExercisesProgress::Pending => println!("Next exercise: {}", app_state.current_exercise()), } |
