| ... | ... |
@@ -6,6 +6,7 @@ |
| 6 | 6 |
#include <termios.h> |
| 7 | 7 |
#include <sys/ioctl.h> |
| 8 | 8 |
#include <sys/select.h> |
| 9 |
+#include <signal.h> |
|
| 9 | 10 |
|
| 10 | 11 |
#include "tty.h" |
| 11 | 12 |
|
| ... | ... |
@@ -21,6 +22,10 @@ void tty_close(tty_t *tty) {
|
| 21 | 22 |
close(tty->fdin); |
| 22 | 23 |
} |
| 23 | 24 |
|
| 25 |
+static void handle_sigwinch(int sig){
|
|
| 26 |
+ (void)sig; |
|
| 27 |
+} |
|
| 28 |
+ |
|
| 24 | 29 |
void tty_init(tty_t *tty, const char *tty_filename) {
|
| 25 | 30 |
tty->fdin = open(tty_filename, O_RDONLY); |
| 26 | 31 |
if (tty->fdin < 0) {
|
| ... | ... |
@@ -62,6 +67,8 @@ void tty_init(tty_t *tty, const char *tty_filename) {
|
| 62 | 67 |
tty_getwinsz(tty); |
| 63 | 68 |
|
| 64 | 69 |
tty_setnormal(tty); |
| 70 |
+ |
|
| 71 |
+ signal(SIGWINCH, handle_sigwinch); |
|
| 65 | 72 |
} |
| 66 | 73 |
|
| 67 | 74 |
void tty_getwinsz(tty_t *tty) {
|
| ... | ... |
@@ -89,14 +96,19 @@ char tty_getchar(tty_t *tty) {
|
| 89 | 96 |
} |
| 90 | 97 |
} |
| 91 | 98 |
|
| 92 |
-int tty_input_ready(tty_t *tty, unsigned long timeout) {
|
|
| 99 |
+int tty_input_ready(tty_t *tty, unsigned long timeout, int return_on_signal) {
|
|
| 93 | 100 |
fd_set readfs; |
| 94 | 101 |
FD_ZERO(&readfs); |
| 95 | 102 |
FD_SET(tty->fdin, &readfs); |
| 96 | 103 |
|
| 97 | 104 |
struct timespec ts = {timeout / 1000, (timeout % 1000) * 1000000};
|
| 98 | 105 |
|
| 99 |
- int err = pselect(tty->fdin + 1, &readfs, NULL, NULL, &ts, NULL); |
|
| 106 |
+ sigset_t mask; |
|
| 107 |
+ sigemptyset(&mask); |
|
| 108 |
+ if (!return_on_signal) |
|
| 109 |
+ sigaddset(&mask, SIGWINCH); |
|
| 110 |
+ |
|
| 111 |
+ int err = pselect(tty->fdin + 1, &readfs, NULL, NULL, &ts, &mask); |
|
| 100 | 112 |
|
| 101 | 113 |
if (err < 0) {
|
| 102 | 114 |
return 0; |
| ... | ... |
@@ -17,7 +17,7 @@ void tty_close(tty_t *tty); |
| 17 | 17 |
void tty_init(tty_t *tty, const char *tty_filename); |
| 18 | 18 |
void tty_getwinsz(tty_t *tty); |
| 19 | 19 |
char tty_getchar(tty_t *tty); |
| 20 |
-int tty_input_ready(tty_t *tty, unsigned long timeout); |
|
| 20 |
+int tty_input_ready(tty_t *tty, int timeout, int return_on_signal); |
|
| 21 | 21 |
|
| 22 | 22 |
void tty_setfg(tty_t *tty, int fg); |
| 23 | 23 |
void tty_setinvert(tty_t *tty); |
| ... | ... |
@@ -373,7 +373,7 @@ int tty_interface_run(tty_interface_t *state) {
|
| 373 | 373 |
return state->exit; |
| 374 | 374 |
|
| 375 | 375 |
draw(state); |
| 376 |
- } while (tty_input_ready(state->tty, state->ambiguous_key_pending ? KEYTIMEOUT : 0)); |
|
| 376 |
+ } while (tty_input_ready(state->tty, state->ambiguous_key_pending ? KEYTIMEOUT : 0, 0)); |
|
| 377 | 377 |
|
| 378 | 378 |
if (state->ambiguous_key_pending) {
|
| 379 | 379 |
char s[1] = ""; |