Skip to content

Commit

Permalink
Introduce Event::Timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Dec 14, 2024
1 parent 792f9a7 commit 1807fe0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl<'b> InputState<'b> {
tty::Event::ExternalPrint(msg) => {
wrt.external_print(msg)?;
}
_ => {}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/tty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub trait RawMode: Sized {
pub enum Event {
KeyPress(KeyEvent),
ExternalPrint(String),

Check warning on line 21 in src/tty/mod.rs

View workflow job for this annotation

GitHub Actions / Test min versions

field `0` is never read
#[cfg(unix)]
Timeout(bool),
}

/// Translate bytes read from stdin to keys.
Expand Down
9 changes: 3 additions & 6 deletions src/tty/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 1807fe0

Please sign in to comment.