--- embedaddon/readline/examples/rl-callbacktest.c 2014/07/30 08:16:46 1.1.1.1 +++ embedaddon/readline/examples/rl-callbacktest.c 2021/03/17 01:01:01 1.1.1.2 @@ -2,11 +2,15 @@ #include #include #include +#include /* Used for select(2) */ #include #include +#include + +#include #include /* Standard readline include files. */ @@ -18,11 +22,22 @@ # include #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 ();