diff options
Diffstat (limited to 'examples/rl-callbacktest.c')
-rw-r--r-- | examples/rl-callbacktest.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/examples/rl-callbacktest.c b/examples/rl-callbacktest.c index 87a781d..3525ffd 100644 --- a/examples/rl-callbacktest.c +++ b/examples/rl-callbacktest.c @@ -2,11 +2,15 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> +#include <locale.h> /* Used for select(2) */ #include <sys/types.h> #include <sys/select.h> +#include <signal.h> + +#include <errno.h> #include <stdio.h> /* Standard readline include files. */ @@ -18,11 +22,22 @@ # include <readline/history.h> #endif +extern int errno; + static void cb_linehandler (char *); +static void signandler (int); -int running; +int running, sigwinch_received; const char *prompt = "rltest$ "; +/* Handle SIGWINCH and window size changes when readline is not active and + reading a character. */ +static void +sighandler (int sig) +{ + sigwinch_received = 1; +} + /* Callback function called for each line when accept-line executed, EOF seen, or EOF character read. This sets a flag and returns; it could also call exit(3). */ @@ -57,6 +72,12 @@ main (int c, char **v) fd_set fds; int r; + + setlocale (LC_ALL, ""); + + /* Handle SIGWINCH */ + signal (SIGWINCH, sighandler); + /* Install the line handler. */ rl_callback_handler_install (prompt, cb_linehandler); @@ -71,12 +92,19 @@ main (int c, char **v) FD_SET (fileno (rl_instream), &fds); r = select (FD_SETSIZE, &fds, NULL, NULL, NULL); - if (r < 0) + if (r < 0 && errno != EINTR) { perror ("rltest: select"); rl_callback_handler_remove (); break; } + if (sigwinch_received) + { + rl_resize_terminal (); + sigwinch_received = 0; + } + if (r < 0) + continue; if (FD_ISSET (fileno (rl_instream), &fds)) rl_callback_read_char (); |