Skip to content

Commit dcad002

Browse files
committed
Only render when needed
1 parent 51b8d2a commit dcad002

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/app_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ const STATE_FILE_NAME: &str = ".rustlings-state.txt";
2424
pub enum ExercisesProgress {
2525
// All exercises are done.
2626
AllDone,
27-
// The current exercise failed and is still pending.
28-
CurrentPending,
2927
// A new exercise is now pending.
3028
NewPending,
29+
// The current exercise is still pending.
30+
CurrentPending,
3131
}
3232

3333
pub enum StateFileStatus {

src/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn run(app_state: &mut AppState) -> Result<()> {
4545
}
4646

4747
match app_state.done_current_exercise(&mut stdout)? {
48-
ExercisesProgress::CurrentPending | ExercisesProgress::NewPending => {
48+
ExercisesProgress::NewPending | ExercisesProgress::CurrentPending => {
4949
stdout.write_all(b"Next exercise: ")?;
5050
app_state
5151
.current_exercise()

src/watch.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,11 @@ fn run_watch(
8383
match event {
8484
WatchEvent::Input(InputEvent::Next) => match watch_state.next_exercise(&mut stdout)? {
8585
ExercisesProgress::AllDone => break,
86-
ExercisesProgress::CurrentPending => watch_state.render(&mut stdout)?,
8786
ExercisesProgress::NewPending => watch_state.run_current_exercise(&mut stdout)?,
87+
ExercisesProgress::CurrentPending => (),
8888
},
8989
WatchEvent::Input(InputEvent::Hint) => watch_state.show_hint(&mut stdout)?,
90-
WatchEvent::Input(InputEvent::List) => {
91-
return Ok(WatchExit::List);
92-
}
90+
WatchEvent::Input(InputEvent::List) => return Ok(WatchExit::List),
9391
WatchEvent::Input(InputEvent::Quit) => {
9492
stdout.write_all(QUIT_MSG)?;
9593
break;
@@ -99,9 +97,7 @@ fn run_watch(
9997
watch_state.handle_file_change(exercise_ind, &mut stdout)?;
10098
}
10199
WatchEvent::TerminalResize => watch_state.render(&mut stdout)?,
102-
WatchEvent::NotifyErr(e) => {
103-
return Err(Error::from(e).context(NOTIFY_ERR));
104-
}
100+
WatchEvent::NotifyErr(e) => return Err(Error::from(e).context(NOTIFY_ERR)),
105101
WatchEvent::TerminalEventErr(e) => {
106102
return Err(Error::from(e).context("Terminal event listener failed"));
107103
}

src/watch/state.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ impl<'a> WatchState<'a> {
195195
}
196196

197197
pub fn show_hint(&mut self, stdout: &mut StdoutLock) -> io::Result<()> {
198-
self.show_hint = true;
199-
self.render(stdout)
198+
if !self.show_hint {
199+
self.show_hint = true;
200+
self.render(stdout)?;
201+
}
202+
203+
Ok(())
200204
}
201205
}

0 commit comments

Comments
 (0)