Skip to content

Commit ed94caa

Browse files
committed
Merge branch 'master' of https://github.com/mitsuhiko/console
2 parents 995af8f + b1e432a commit ed94caa

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/kb.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ pub enum Key {
2626
PageUp,
2727
PageDown,
2828
Char(char),
29+
CtrlC,
2930
}

src/term.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,15 @@ impl Term {
294294
if !self.is_tty {
295295
Ok(Key::Unknown)
296296
} else {
297-
read_single_key()
297+
read_single_key(false)
298+
}
299+
}
300+
301+
pub fn read_key_raw(&self) -> io::Result<Key> {
302+
if !self.is_tty {
303+
Ok(Key::Unknown)
304+
} else {
305+
read_single_key(true)
298306
}
299307
}
300308

src/unix_term.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ fn read_single_key_impl(fd: i32) -> Result<Key, io::Error> {
295295
}
296296
}
297297

298-
pub fn read_single_key() -> io::Result<Key> {
298+
pub fn read_single_key(ctrlc_key: bool) -> io::Result<Key> {
299299
let tty_f;
300300
let fd = unsafe {
301301
if libc::isatty(libc::STDIN_FILENO) == 1 {
@@ -321,8 +321,12 @@ pub fn read_single_key() -> io::Result<Key> {
321321
// if the user hit ^C we want to signal SIGINT to outselves.
322322
if let Err(ref err) = rv {
323323
if err.kind() == io::ErrorKind::Interrupted {
324-
unsafe {
325-
libc::raise(libc::SIGINT);
324+
if !ctrlc_key {
325+
unsafe {
326+
libc::raise(libc::SIGINT);
327+
}
328+
} else {
329+
return Ok(Key::CtrlC);
326330
}
327331
}
328332
}

0 commit comments

Comments
 (0)