Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mitsuhiko/console
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jan 9, 2024
2 parents 995af8f + b1e432a commit ed94caa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/kb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ pub enum Key {
PageUp,
PageDown,
Char(char),
CtrlC,
}
10 changes: 9 additions & 1 deletion src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Key> {
if !self.is_tty {
Ok(Key::Unknown)
} else {
read_single_key(true)
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/unix_term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ fn read_single_key_impl(fd: i32) -> Result<Key, io::Error> {
}
}

pub fn read_single_key() -> io::Result<Key> {
pub fn read_single_key(ctrlc_key: bool) -> io::Result<Key> {
let tty_f;
let fd = unsafe {
if libc::isatty(libc::STDIN_FILENO) == 1 {
Expand All @@ -321,8 +321,12 @@ pub fn read_single_key() -> io::Result<Key> {
// 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);
}
}
}
Expand Down

0 comments on commit ed94caa

Please sign in to comment.