From 61d40f406fa254e57bb491f4c127132909eb3a15 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 6 May 2019 00:52:13 +0200 Subject: [PATCH] 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 --- examples/cli.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/examples/cli.c b/examples/cli.c index 3bcafed..a0128b2 100644 --- a/examples/cli.c +++ b/examples/cli.c @@ -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);