diff options
Diffstat (limited to 'src/tty.c')
-rw-r--r-- | src/tty.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -6,6 +6,7 @@ #include <termios.h> #include <sys/ioctl.h> #include <sys/select.h> +#include <signal.h> #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; |