1 /* Standard include files. stdio.h is required. */
7 /* Used for select(2) */
9 #include <sys/select.h>
16 /* Standard readline include files. */
17 #if defined (READLINE_LIBRARY)
18 # include "readline.h"
21 # include <readline/readline.h>
22 # include <readline/history.h>
27 static void cb_linehandler (char *);
28 static void signandler (int);
30 int running
, sigwinch_received
;
31 const char *prompt
= "rltest$ ";
33 /* Handle SIGWINCH and window size changes when readline is not active and
34 reading a character. */
38 sigwinch_received
= 1;
41 /* Callback function called for each line when accept-line executed, EOF
42 seen, or EOF character read. This sets a flag and returns; it could
45 cb_linehandler (char *line
)
47 /* Can use ^D (stty eof) or `exit' to exit. */
48 if (line
== NULL
|| strcmp (line
, "exit") == 0)
53 /* This function needs to be called to reset the terminal settings,
54 and calling it from the line handler keeps one extra prompt from
56 rl_callback_handler_remove ();
64 printf ("input line: %s\n", line
);
70 main (int c
, char **v
)
76 setlocale (LC_ALL
, "");
79 signal (SIGWINCH
, sighandler
);
81 /* Install the line handler. */
82 rl_callback_handler_install (prompt
, cb_linehandler
);
84 /* Enter a simple event loop. This waits until something is available
85 to read on readline's input stream (defaults to standard input) and
86 calls the builtin character read callback to read it. It does not
87 have to modify the user's terminal settings. */
92 FD_SET (fileno (rl_instream
), &fds
);
94 r
= select (FD_SETSIZE
, &fds
, NULL
, NULL
, NULL
);
95 if (r
< 0 && errno
!= EINTR
)
97 perror ("rltest: select");
98 rl_callback_handler_remove ();
101 if (sigwinch_received
)
103 rl_resize_terminal ();
104 sigwinch_received
= 0;
109 if (FD_ISSET (fileno (rl_instream
), &fds
))
110 rl_callback_read_char ();
113 printf ("rltest: Event loop has exited\n");
This page took 0.033368 seconds and 4 git commands to generate.