mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-17 22:58:08 -05:00
Only render when needed
This commit is contained in:
parent
51b8d2ab25
commit
dcad002057
4 changed files with 12 additions and 12 deletions
|
@ -24,10 +24,10 @@ const STATE_FILE_NAME: &str = ".rustlings-state.txt";
|
|||
pub enum ExercisesProgress {
|
||||
// All exercises are done.
|
||||
AllDone,
|
||||
// The current exercise failed and is still pending.
|
||||
CurrentPending,
|
||||
// A new exercise is now pending.
|
||||
NewPending,
|
||||
// The current exercise is still pending.
|
||||
CurrentPending,
|
||||
}
|
||||
|
||||
pub enum StateFileStatus {
|
||||
|
|
|
@ -45,7 +45,7 @@ pub fn run(app_state: &mut AppState) -> Result<()> {
|
|||
}
|
||||
|
||||
match app_state.done_current_exercise(&mut stdout)? {
|
||||
ExercisesProgress::CurrentPending | ExercisesProgress::NewPending => {
|
||||
ExercisesProgress::NewPending | ExercisesProgress::CurrentPending => {
|
||||
stdout.write_all(b"Next exercise: ")?;
|
||||
app_state
|
||||
.current_exercise()
|
||||
|
|
10
src/watch.rs
10
src/watch.rs
|
@ -83,13 +83,11 @@ fn run_watch(
|
|||
match event {
|
||||
WatchEvent::Input(InputEvent::Next) => match watch_state.next_exercise(&mut stdout)? {
|
||||
ExercisesProgress::AllDone => break,
|
||||
ExercisesProgress::CurrentPending => watch_state.render(&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::List) => {
|
||||
return Ok(WatchExit::List);
|
||||
}
|
||||
WatchEvent::Input(InputEvent::List) => return Ok(WatchExit::List),
|
||||
WatchEvent::Input(InputEvent::Quit) => {
|
||||
stdout.write_all(QUIT_MSG)?;
|
||||
break;
|
||||
|
@ -99,9 +97,7 @@ fn run_watch(
|
|||
watch_state.handle_file_change(exercise_ind, &mut stdout)?;
|
||||
}
|
||||
WatchEvent::TerminalResize => watch_state.render(&mut stdout)?,
|
||||
WatchEvent::NotifyErr(e) => {
|
||||
return Err(Error::from(e).context(NOTIFY_ERR));
|
||||
}
|
||||
WatchEvent::NotifyErr(e) => return Err(Error::from(e).context(NOTIFY_ERR)),
|
||||
WatchEvent::TerminalEventErr(e) => {
|
||||
return Err(Error::from(e).context("Terminal event listener failed"));
|
||||
}
|
||||
|
|
|
@ -195,7 +195,11 @@ impl<'a> WatchState<'a> {
|
|||
}
|
||||
|
||||
pub fn show_hint(&mut self, stdout: &mut StdoutLock) -> io::Result<()> {
|
||||
self.show_hint = true;
|
||||
self.render(stdout)
|
||||
if !self.show_hint {
|
||||
self.show_hint = true;
|
||||
self.render(stdout)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue