iomenu

interactive text selection menu
Log | Files | Refs | README | LICENSE

commit 4a488ca1bbb3bf794bccdd502c5c64173f4b5bdb
parent 4ce5703054613b342e3bc0fb1b1d35f510984fbd
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Thu, 18 May 2017 11:53:32 +0200

sigwinch

Diffstat:
Miomenu.c | 22+++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/iomenu.c b/iomenu.c @@ -1,5 +1,6 @@ #include <fcntl.h> #include <locale.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -58,10 +59,6 @@ set_terminal(void) { struct termios new; - /* get window size */ - if (ioctl(tty_fd, TIOCGWINSZ, &ws) < 0) - die("ioctl"); - /* save cursor postition */ fputs("\033[s", stderr); @@ -434,7 +431,6 @@ input_get(void) input[0] = '\0'; - print_screen(); while ((exit_code = input_key()) == CONTINUE) print_screen(); @@ -445,6 +441,21 @@ input_get(void) static void +sigwinch() +{ + extern struct winsize ws; + + /* get window size */ + if (ioctl(tty_fd, TIOCGWINSZ, &ws) < 0) + die("ioctl"); + + print_screen(); + + signal(SIGWINCH, sigwinch); +} + + +static void usage(void) { fprintf(stderr, "%s [-b] [-t] [-s] [-l lines] [-p prompt]\n", argv0); @@ -505,6 +516,7 @@ main(int argc, char *argv[]) tty_fd = open("/dev/tty", O_RDWR); set_terminal(); + sigwinch(); exit_code = input_get(); /* main loop */ reset_terminal(); close(tty_fd);