Only render when needed

This commit is contained in:
mo8it 2024-09-05 17:32:59 +02:00
parent 51b8d2ab25
commit dcad002057
4 changed files with 12 additions and 12 deletions

View file

@ -24,10 +24,10 @@ const STATE_FILE_NAME: &str = ".rustlings-state.txt";
pub enum ExercisesProgress { pub enum ExercisesProgress {
// All exercises are done. // All exercises are done.
AllDone, AllDone,
// The current exercise failed and is still pending.
CurrentPending,
// A new exercise is now pending. // A new exercise is now pending.
NewPending, NewPending,
// The current exercise is still pending.
CurrentPending,
} }
pub enum StateFileStatus { pub enum StateFileStatus {

View file

@ -45,7 +45,7 @@ pub fn run(app_state: &mut AppState) -> Result<()> {
} }
match app_state.done_current_exercise(&mut stdout)? { match app_state.done_current_exercise(&mut stdout)? {
ExercisesProgress::CurrentPending | ExercisesProgress::NewPending => { ExercisesProgress::NewPending | ExercisesProgress::CurrentPending => {
stdout.write_all(b"Next exercise: ")?; stdout.write_all(b"Next exercise: ")?;
app_state app_state
.current_exercise() .current_exercise()

View file

@ -83,13 +83,11 @@ fn run_watch(
match event { match event {
WatchEvent::Input(InputEvent::Next) => match watch_state.next_exercise(&mut stdout)? { WatchEvent::Input(InputEvent::Next) => match watch_state.next_exercise(&mut stdout)? {
ExercisesProgress::AllDone => break, ExercisesProgress::AllDone => break,
ExercisesProgress::CurrentPending => watch_state.render(&mut stdout)?,
ExercisesProgress::NewPending => watch_state.run_current_exercise(&mut stdout)?, ExercisesProgress::NewPending => watch_state.run_current_exercise(&mut stdout)?,
ExercisesProgress::CurrentPending => (),
}, },
WatchEvent::Input(InputEvent::Hint) => watch_state.show_hint(&mut stdout)?, WatchEvent::Input(InputEvent::Hint) => watch_state.show_hint(&mut stdout)?,
WatchEvent::Input(InputEvent::List) => { WatchEvent::Input(InputEvent::List) => return Ok(WatchExit::List),
return Ok(WatchExit::List);
}
WatchEvent::Input(InputEvent::Quit) => { WatchEvent::Input(InputEvent::Quit) => {
stdout.write_all(QUIT_MSG)?; stdout.write_all(QUIT_MSG)?;
break; break;
@ -99,9 +97,7 @@ fn run_watch(
watch_state.handle_file_change(exercise_ind, &mut stdout)?; watch_state.handle_file_change(exercise_ind, &mut stdout)?;
} }
WatchEvent::TerminalResize => watch_state.render(&mut stdout)?, WatchEvent::TerminalResize => watch_state.render(&mut stdout)?,
WatchEvent::NotifyErr(e) => { WatchEvent::NotifyErr(e) => return Err(Error::from(e).context(NOTIFY_ERR)),
return Err(Error::from(e).context(NOTIFY_ERR));
}
WatchEvent::TerminalEventErr(e) => { WatchEvent::TerminalEventErr(e) => {
return Err(Error::from(e).context("Terminal event listener failed")); return Err(Error::from(e).context("Terminal event listener failed"));
} }

View file

@ -195,7 +195,11 @@ impl<'a> WatchState<'a> {
} }
pub fn show_hint(&mut self, stdout: &mut StdoutLock) -> io::Result<()> { pub fn show_hint(&mut self, stdout: &mut StdoutLock) -> io::Result<()> {
self.show_hint = true; if !self.show_hint {
self.render(stdout) self.show_hint = true;
self.render(stdout)?;
}
Ok(())
} }
} }