diff --git a/src/kb.rs b/src/kb.rs index 5258c135..2a0f61ed 100644 --- a/src/kb.rs +++ b/src/kb.rs @@ -26,4 +26,5 @@ pub enum Key { PageUp, PageDown, Char(char), + CtrlC, } diff --git a/src/term.rs b/src/term.rs index 4ccafb61..9ae2aba2 100644 --- a/src/term.rs +++ b/src/term.rs @@ -294,7 +294,15 @@ impl Term { if !self.is_tty { Ok(Key::Unknown) } else { - read_single_key() + read_single_key(false) + } + } + + pub fn read_key_raw(&self) -> io::Result { + if !self.is_tty { + Ok(Key::Unknown) + } else { + read_single_key(true) } } diff --git a/src/unix_term.rs b/src/unix_term.rs index 487d453f..77623e34 100644 --- a/src/unix_term.rs +++ b/src/unix_term.rs @@ -295,7 +295,7 @@ fn read_single_key_impl(fd: i32) -> Result { } } -pub fn read_single_key() -> io::Result { +pub fn read_single_key(ctrlc_key: bool) -> io::Result { let tty_f; let fd = unsafe { if libc::isatty(libc::STDIN_FILENO) == 1 { @@ -321,8 +321,12 @@ pub fn read_single_key() -> io::Result { // if the user hit ^C we want to signal SIGINT to outselves. if let Err(ref err) = rv { if err.kind() == io::ErrorKind::Interrupted { - unsafe { - libc::raise(libc::SIGINT); + if !ctrlc_key { + unsafe { + libc::raise(libc::SIGINT); + } + } else { + return Ok(Key::CtrlC); } } }