mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-02 16:33:30 +02:00
Add command to check all the exercises
This allows for skipping repeating "next" when multiple exercises are done at once, or when earlier exercises have been updated/changed (and thus must be redone) while still working of the whole set (i.e. the final check_all is not yet available to flag those undone exercises)
This commit is contained in:
@@ -195,6 +195,11 @@ impl<'a> WatchState<'a> {
|
||||
stdout.queue(ResetColor)?;
|
||||
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)?;
|
||||
@@ -274,6 +279,23 @@ impl<'a> WatchState<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn check_all_exercises(&mut self, stdout: &mut StdoutLock) -> Result<ExercisesProgress> {
|
||||
stdout.write_all(b"\n")?;
|
||||
|
||||
if let Some(first_fail) = self.app_state.check_all_exercises(stdout, false)? {
|
||||
// Only change exercise if the current one is done...
|
||||
if self.app_state.current_exercise().done {
|
||||
self.app_state.set_current_exercise_ind(first_fail)?;
|
||||
}
|
||||
// ...but always pretend it's a "new" anyway because that refreshes
|
||||
// the display
|
||||
Ok(ExercisesProgress::NewPending)
|
||||
} 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user