mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-02 16:33:30 +02:00
Improve input handling
This commit is contained in:
+1
-12
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user