From 1807fe0ea64bf6c06c11f1bc1ed0c08c1f3e0b93 Mon Sep 17 00:00:00 2001 From: gwenn Date: Sat, 14 Dec 2024 15:50:07 +0100 Subject: [PATCH] Introduce Event::Timeout --- src/keymap.rs | 1 + src/tty/mod.rs | 2 ++ src/tty/unix.rs | 9 +++------ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/keymap.rs b/src/keymap.rs index 784c91016..5be616001 100644 --- a/src/keymap.rs +++ b/src/keymap.rs @@ -441,6 +441,7 @@ impl<'b> InputState<'b> { tty::Event::ExternalPrint(msg) => { wrt.external_print(msg)?; } + _ => {} } } } diff --git a/src/tty/mod.rs b/src/tty/mod.rs index 62484f042..37f80936e 100644 --- a/src/tty/mod.rs +++ b/src/tty/mod.rs @@ -19,6 +19,8 @@ pub trait RawMode: Sized { pub enum Event { KeyPress(KeyEvent), ExternalPrint(String), + #[cfg(unix)] + Timeout(bool), } /// Translate bytes read from stdin to keys. diff --git a/src/tty/unix.rs b/src/tty/unix.rs index 3ec5a74b1..c8b82ec9a 100644 --- a/src/tty/unix.rs +++ b/src/tty/unix.rs @@ -716,8 +716,7 @@ impl PosixRawReader { if self.is_dev_tty { // poll doesn't work for /dev/tty on MacOS but select does return Ok(match self.select(Some(timeout), false /* ignored */)? { - // ugly but ESC means timeout... - Event::KeyPress(KeyEvent::ESC) => false, + Event::Timeout(true) => false, _ => true, }); } @@ -784,15 +783,13 @@ impl PosixRawReader { return Err(ReadlineError::WindowResized); } else if readfds.contains(tty_in) { if timeout.is_some() { - // ugly but ENTER means success (no timeout)... - return Ok(Event::KeyPress(KeyEvent::ENTER)); + return Ok(Event::Timeout(false)); } else { // prefer user input over external print return self.next_key(single_esc_abort).map(Event::KeyPress); } } else if timeout.is_some() { - // ugly but ESC means timeout... - return Ok(Event::KeyPress(KeyEvent::ESC)); + return Ok(Event::Timeout(true)); } else if let Some(ref pipe_reader) = self.pipe_reader { let mut guard = pipe_reader.lock().unwrap(); let mut buf = [0; 1];