From c173310a093ba1277f419190ecaa36cdb97455a6 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sat, 15 Sep 2018 14:15:28 -0700 Subject: Allow masking signals in tty_input_ready --- src/tty.c | 16 ++++++++++++++-- src/tty.h | 2 +- src/tty_interface.c | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/tty.c b/src/tty.c index 5d7da64..a81fe85 100644 --- a/src/tty.c +++ b/src/tty.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "tty.h" @@ -21,6 +22,10 @@ void tty_close(tty_t *tty) { close(tty->fdin); } +static void handle_sigwinch(int sig){ + (void)sig; +} + void tty_init(tty_t *tty, const char *tty_filename) { tty->fdin = open(tty_filename, O_RDONLY); if (tty->fdin < 0) { @@ -62,6 +67,8 @@ void tty_init(tty_t *tty, const char *tty_filename) { tty_getwinsz(tty); tty_setnormal(tty); + + signal(SIGWINCH, handle_sigwinch); } void tty_getwinsz(tty_t *tty) { @@ -89,14 +96,19 @@ char tty_getchar(tty_t *tty) { } } -int tty_input_ready(tty_t *tty, unsigned long timeout) { +int tty_input_ready(tty_t *tty, unsigned long timeout, int return_on_signal) { fd_set readfs; FD_ZERO(&readfs); FD_SET(tty->fdin, &readfs); struct timespec ts = {timeout / 1000, (timeout % 1000) * 1000000}; - int err = pselect(tty->fdin + 1, &readfs, NULL, NULL, &ts, NULL); + sigset_t mask; + sigemptyset(&mask); + if (!return_on_signal) + sigaddset(&mask, SIGWINCH); + + int err = pselect(tty->fdin + 1, &readfs, NULL, NULL, &ts, &mask); if (err < 0) { return 0; diff --git a/src/tty.h b/src/tty.h index a21687d..66f48b9 100644 --- a/src/tty.h +++ b/src/tty.h @@ -17,7 +17,7 @@ void tty_close(tty_t *tty); void tty_init(tty_t *tty, const char *tty_filename); void tty_getwinsz(tty_t *tty); char tty_getchar(tty_t *tty); -int tty_input_ready(tty_t *tty, unsigned long timeout); +int tty_input_ready(tty_t *tty, int timeout, int return_on_signal); void tty_setfg(tty_t *tty, int fg); void tty_setinvert(tty_t *tty); diff --git a/src/tty_interface.c b/src/tty_interface.c index 5839af7..6482c68 100644 --- a/src/tty_interface.c +++ b/src/tty_interface.c @@ -373,7 +373,7 @@ int tty_interface_run(tty_interface_t *state) { return state->exit; draw(state); - } while (tty_input_ready(state->tty, state->ambiguous_key_pending ? KEYTIMEOUT : 0)); + } while (tty_input_ready(state->tty, state->ambiguous_key_pending ? KEYTIMEOUT : 0, 0)); if (state->ambiguous_key_pending) { char s[1] = ""; -- cgit v1.2.3