mirror of
				https://github.com/troglobit/editline.git
				synced 2025-10-31 08:18:11 +08:00 
			
		
		
		
	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:
		| @@ -98,37 +98,29 @@ el_status_t list_possible(void) | |||||||
|     return el_ring_bell(); |     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) | el_status_t do_suspend(void) | ||||||
| { | { | ||||||
|     puts("Abort!"); |     puts("Abort!"); | ||||||
|     return CSstay; |     return CSstay; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static void breakit(int signo) | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
| int main(void) | int main(void) | ||||||
| { | { | ||||||
|     char *line; |     char *line; | ||||||
|     char *prompt = "cli> "; |     char *prompt = "cli> "; | ||||||
|     char *passwd = "Enter password: "; |     char *passwd = "Enter password: "; | ||||||
|  |  | ||||||
|  |     signal(SIGINT, breakit); | ||||||
|  |  | ||||||
|     /* Setup callbacks */ |     /* Setup callbacks */ | ||||||
|     rl_set_complete_func(&my_rl_complete); |     rl_set_complete_func(&my_rl_complete); | ||||||
|     rl_set_list_possib_func(&my_rl_list_possib); |     rl_set_list_possib_func(&my_rl_list_possib); | ||||||
|  |  | ||||||
|     el_bind_key('?', list_possible); |     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); |     el_bind_key(CTL('Z'), do_suspend); | ||||||
|     read_history(HISTORY); |     read_history(HISTORY); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Joachim Nilsson
					Joachim Nilsson