examples: Catch SIGINT instead of mapping Ctrl-C, use default Ctrl-D

We want Ctrl-C to work as in Bash, so let's just catch SIGINT (and do
nothing).  Also, the default Ctrl-D handler does what we want, i.e.
exit the CLI when we're on an empty line.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-05-06 00:52:13 +02:00
parent 385cd77e9b
commit 61d40f406f

View File

@ -98,37 +98,29 @@ el_status_t list_possible(void)
return el_ring_bell();
}
el_status_t do_break(void)
{
puts("Breakout!");
return CSeof;
}
el_status_t do_exit(void)
{
puts("Bye bye!");
return CSeof;
}
el_status_t do_suspend(void)
{
puts("Abort!");
return CSstay;
}
static void breakit(int signo)
{
}
int main(void)
{
char *line;
char *prompt = "cli> ";
char *passwd = "Enter password: ";
signal(SIGINT, breakit);
/* Setup callbacks */
rl_set_complete_func(&my_rl_complete);
rl_set_list_possib_func(&my_rl_list_possib);
el_bind_key('?', list_possible);
el_bind_key(CTL('C'), do_break);
el_bind_key(CTL('D'), do_exit);
el_bind_key(CTL('Z'), do_suspend);
read_history(HISTORY);