summaryrefslogtreecommitdiff
path: root/src/watch/terminal_event.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/watch/terminal_event.rs')
-rw-r--r--src/watch/terminal_event.rs46
1 files changed, 18 insertions, 28 deletions
diff --git a/src/watch/terminal_event.rs b/src/watch/terminal_event.rs
index 6d790b7..846bec1 100644
--- a/src/watch/terminal_event.rs
+++ b/src/watch/terminal_event.rs
@@ -9,12 +9,10 @@ pub enum InputEvent {
Hint,
List,
Quit,
- Unrecognized(String),
+ Unrecognized(char),
}
pub fn terminal_event_handler(tx: Sender<WatchEvent>, manual_run: bool) {
- let mut input = String::with_capacity(8);
-
let last_input_event = loop {
let terminal_event = match event::read() {
Ok(v) => v,
@@ -28,36 +26,28 @@ pub fn terminal_event_handler(tx: Sender<WatchEvent>, manual_run: bool) {
match terminal_event {
Event::Key(key) => {
- if key.modifiers != KeyModifiers::NONE {
- continue;
- }
-
match key.kind {
- KeyEventKind::Release => continue,
- KeyEventKind::Press | KeyEventKind::Repeat => (),
+ KeyEventKind::Release | KeyEventKind::Repeat => continue,
+ KeyEventKind::Press => (),
}
- match key.code {
- KeyCode::Enter => {
- let input_event = match input.trim() {
- "n" | "next" => InputEvent::Next,
- "h" | "hint" => InputEvent::Hint,
- "l" | "list" => break InputEvent::List,
- "q" | "quit" => break InputEvent::Quit,
- "r" | "run" if manual_run => InputEvent::Run,
- _ => InputEvent::Unrecognized(input.clone()),
- };
-
- if tx.send(WatchEvent::Input(input_event)).is_err() {
- return;
- }
+ if key.modifiers != KeyModifiers::NONE {
+ continue;
+ }
- input.clear();
- }
- KeyCode::Char(c) => {
- input.push(c);
+ if let KeyCode::Char(c) = key.code {
+ let input_event = match c {
+ 'n' => InputEvent::Next,
+ 'h' => InputEvent::Hint,
+ 'l' => break InputEvent::List,
+ 'q' => break InputEvent::Quit,
+ 'r' if manual_run => InputEvent::Run,
+ _ => InputEvent::Unrecognized(c),
+ };
+
+ if tx.send(WatchEvent::Input(input_event)).is_err() {
+ return;
}
- _ => (),
}
}
Event::Resize(_, _) => {