Improve input handling

This commit is contained in:
mo8it
2024-05-13 02:32:25 +02:00
parent 0525739046
commit f9e35a4344
5 changed files with 18 additions and 22 deletions
+1 -12
View File
@@ -78,10 +78,7 @@ impl<'a> WatchState<'a> {
pub fn next_exercise(&mut self) -> Result<ExercisesProgress> {
if matches!(self.done_status, DoneStatus::Pending) {
self.writer
.write_all(b"The current exercise isn't done yet\n")?;
self.show_prompt()?;
return Ok(ExercisesProgress::Pending);
return Ok(ExercisesProgress::CurrentPending);
}
self.app_state.done_current_exercise(&mut self.writer)
@@ -165,12 +162,4 @@ When you are done experimenting, enter `n` (or `next`) to move on to the next ex
self.show_hint = true;
self.render()
}
pub fn handle_invalid_input(&mut self, input: char) -> io::Result<()> {
writeln!(
self.writer,
"Invalid input: {input} (confusing input can occur after resizing the terminal)",
)?;
self.show_prompt()
}
}
+2 -2
View File
@@ -9,7 +9,7 @@ pub enum InputEvent {
Hint,
List,
Quit,
Unrecognized(char),
Unrecognized,
}
pub fn terminal_event_handler(tx: Sender<WatchEvent>, manual_run: bool) {
@@ -42,7 +42,7 @@ pub fn terminal_event_handler(tx: Sender<WatchEvent>, manual_run: bool) {
'l' => break InputEvent::List,
'q' => break InputEvent::Quit,
'r' if manual_run => InputEvent::Run,
_ => InputEvent::Unrecognized(c),
_ => InputEvent::Unrecognized,
};
if tx.send(WatchEvent::Input(input_event)).is_err() {