Skip to content

Commit aa3eda7

Browse files
committed
Simplify handling terminal events for unbuffered stdin
1 parent 2d0860f commit aa3eda7

File tree

2 files changed

+6
-37
lines changed

2 files changed

+6
-37
lines changed

src/watch.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ fn run_watch(
9595
break;
9696
}
9797
WatchEvent::Input(InputEvent::Run) => watch_state.run_current_exercise(&mut stdout)?,
98-
WatchEvent::Input(InputEvent::Unrecognized) => watch_state.render(&mut stdout)?,
9998
WatchEvent::FileChange { exercise_ind } => {
10099
watch_state.handle_file_change(exercise_ind, &mut stdout)?;
101100
}

src/watch/terminal_event.rs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@ pub enum InputEvent {
99
Hint,
1010
List,
1111
Quit,
12-
Unrecognized,
1312
}
1413

1514
pub fn terminal_event_handler(tx: Sender<WatchEvent>, manual_run: bool) {
16-
// Only send `Unrecognized` on ENTER if the last input wasn't valid.
17-
let mut last_input_valid = false;
18-
1915
let last_input_event = loop {
2016
let terminal_event = match event::read() {
2117
Ok(v) => v,
@@ -34,39 +30,13 @@ pub fn terminal_event_handler(tx: Sender<WatchEvent>, manual_run: bool) {
3430
KeyEventKind::Press => (),
3531
}
3632

37-
if key.modifiers != KeyModifiers::NONE {
38-
last_input_valid = false;
39-
continue;
40-
}
41-
4233
let input_event = match key.code {
43-
KeyCode::Enter => {
44-
if last_input_valid {
45-
continue;
46-
}
47-
48-
InputEvent::Unrecognized
49-
}
50-
KeyCode::Char(c) => {
51-
let input_event = match c {
52-
'n' => InputEvent::Next,
53-
'h' => InputEvent::Hint,
54-
'l' => break InputEvent::List,
55-
'q' => break InputEvent::Quit,
56-
'r' if manual_run => InputEvent::Run,
57-
_ => {
58-
last_input_valid = false;
59-
continue;
60-
}
61-
};
62-
63-
last_input_valid = true;
64-
input_event
65-
}
66-
_ => {
67-
last_input_valid = false;
68-
continue;
69-
}
34+
KeyCode::Char('n') => InputEvent::Next,
35+
KeyCode::Char('h') => InputEvent::Hint,
36+
KeyCode::Char('l') => break InputEvent::List,
37+
KeyCode::Char('q') => break InputEvent::Quit,
38+
KeyCode::Char('r') if manual_run => InputEvent::Run,
39+
_ => continue,
7040
};
7141

7242
if tx.send(WatchEvent::Input(input_event)).is_err() {

0 commit comments

Comments
 (0)