summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-09-05 17:32:59 +0200
committermo8it <mo8it@proton.me>2024-09-05 17:32:59 +0200
commitdcad002057acfb1a41513fb421275116ea946ca3 (patch)
treec8e11f7584ad1c1d3f04a99d410435fe374e21c8
parent51b8d2ab2542eb6115bbfdbe7a404993dfcd0749 (diff)
Only render when needed
-rw-r--r--src/app_state.rs4
-rw-r--r--src/run.rs2
-rw-r--r--src/watch.rs10
-rw-r--r--src/watch/state.rs8
4 files changed, 12 insertions, 12 deletions
diff --git a/src/app_state.rs b/src/app_state.rs
index 7123d11..ed723c2 100644
--- a/src/app_state.rs
+++ b/src/app_state.rs
@@ -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 {
diff --git a/src/run.rs b/src/run.rs
index f0faa69..a969164 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -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()
diff --git a/src/watch.rs b/src/watch.rs
index ee5dd74..bca3832 100644
--- a/src/watch.rs
+++ b/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"));
}
diff --git a/src/watch/state.rs b/src/watch/state.rs
index fe9e274..75a0c9e 100644
--- a/src/watch/state.rs
+++ b/src/watch/state.rs
@@ -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(())
}
}