summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2018-09-15 14:15:28 -0700
committerJohn Hawthorn <john@hawthorn.email>2018-09-23 11:23:53 -0700
commitc173310a093ba1277f419190ecaa36cdb97455a6 (patch)
tree142e274b822bb0d9ac0e534a74ad866d441c7473 /src
parentdc0a9a8e2d56ad9d7b7879fac9935787ce7e8043 (diff)
Allow masking signals in tty_input_ready
Diffstat (limited to 'src')
-rw-r--r--src/tty.c16
-rw-r--r--src/tty.h2
-rw-r--r--src/tty_interface.c2
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 <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;
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] = "";