diff options
| author | Mo <76752051+mo8it@users.noreply.github.com> | 2024-10-14 01:29:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-14 01:29:25 +0200 |
| commit | baeeff389c95ba145e3383ec1f1357e078d0bbca (patch) | |
| tree | 4d3157197acaf9705c5d1da17b3e6c5c28dc495b /src/watch | |
| parent | 84a42a2b24687ed11f4d2a5c9b624d00b74de916 (diff) | |
| parent | 932bc25d8824e18debc91e5f25f022e8d066bcf8 (diff) | |
Merge pull request #2122 from Nahor/check_all
Improvement to "check all exercises"
Diffstat (limited to 'src/watch')
| -rw-r--r-- | src/watch/state.rs | 26 | ||||
| -rw-r--r-- | src/watch/terminal_event.rs | 2 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/watch/state.rs b/src/watch/state.rs index 19910f0..0ac758c 100644 --- a/src/watch/state.rs +++ b/src/watch/state.rs @@ -157,8 +157,9 @@ impl<'a> WatchState<'a> { /// Move on to the next exercise if the current one is done. pub fn next_exercise(&mut self, stdout: &mut StdoutLock) -> Result<ExercisesProgress> { - if self.done_status == DoneStatus::Pending { - return Ok(ExercisesProgress::CurrentPending); + match self.done_status { + DoneStatus::DoneWithSolution(_) | DoneStatus::DoneWithoutSolution => (), + DoneStatus::Pending => return Ok(ExercisesProgress::CurrentPending), } self.app_state.done_current_exercise::<true>(stdout) @@ -196,6 +197,11 @@ impl<'a> WatchState<'a> { stdout.write_all(b":list / ")?; stdout.queue(SetAttribute(Attribute::Bold))?; + stdout.write_all(b"c")?; + stdout.queue(ResetColor)?; + stdout.write_all(b":check all / ")?; + + stdout.queue(SetAttribute(Attribute::Bold))?; stdout.write_all(b"x")?; stdout.queue(ResetColor)?; stdout.write_all(b":reset / ")?; @@ -274,6 +280,22 @@ impl<'a> WatchState<'a> { Ok(()) } + pub fn check_all_exercises(&mut self, stdout: &mut StdoutLock) -> Result<ExercisesProgress> { + if let Some(first_pending_exercise_ind) = self.app_state.check_all_exercises(stdout)? { + // Only change exercise if the current one is done. + if self.app_state.current_exercise().done { + self.app_state + .set_current_exercise_ind(first_pending_exercise_ind)?; + Ok(ExercisesProgress::NewPending) + } else { + Ok(ExercisesProgress::CurrentPending) + } + } else { + self.app_state.render_final_message(stdout)?; + Ok(ExercisesProgress::AllDone) + } + } + pub fn update_term_width(&mut self, width: u16, stdout: &mut StdoutLock) -> io::Result<()> { if self.term_width != width { self.term_width = width; diff --git a/src/watch/terminal_event.rs b/src/watch/terminal_event.rs index 1ed681d..48411db 100644 --- a/src/watch/terminal_event.rs +++ b/src/watch/terminal_event.rs @@ -11,6 +11,7 @@ pub enum InputEvent { Run, Hint, List, + CheckAll, Reset, Quit, } @@ -37,6 +38,7 @@ pub fn terminal_event_handler( KeyCode::Char('r') if manual_run => InputEvent::Run, KeyCode::Char('h') => InputEvent::Hint, KeyCode::Char('l') => break WatchEvent::Input(InputEvent::List), + KeyCode::Char('c') => InputEvent::CheckAll, KeyCode::Char('x') => { if sender.send(WatchEvent::Input(InputEvent::Reset)).is_err() { return; |
