From: Jaakko Heinonen Date: Tue, 12 Mar 2002 18:54:29 +0000 (+0000) Subject: cancel key support added X-Git-Tag: upstream/0.6.1~2^2~284 X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=4128f78f5543bebc7cd1868736855207019f1f71;p=pkg%2Fabook.git cancel key support added --- diff --git a/abook_rl.c b/abook_rl.c index be8ac90..43ab31a 100644 --- a/abook_rl.c +++ b/abook_rl.c @@ -33,6 +33,8 @@ static int rl_x, rl_y; static WINDOW *rl_win; +static bool rl_cancelled; + static void rl_refresh() { @@ -58,26 +60,36 @@ rline_update() rl_refresh(); } -void +static void rline_compdisp(char **matches, int n, int max_len) { - /* - * dummy - */ + /* dummy */ +} + +static int +rl_cancel(int dummy1, int dummy2) +{ + rl_cancelled = TRUE; + + rl_done = 1; + + return 0; } static void -abook_rl_init(int use_completion) +abook_rl_init(bool use_completion) { rl_readline_name = RL_READLINE_NAME; rl_already_prompted = 1; + rl_catch_sigwinch = 0; rl_redisplay_function = rline_update; rl_completion_display_matches_hook = rline_compdisp; - + rl_unbind_function_in_map(rl_clear_screen, rl_get_keymap()); rl_unbind_function_in_map(rl_reverse_search_history, rl_get_keymap()); + rl_unbind_function_in_map(rl_re_read_init_file, rl_get_keymap()); if(use_completion) { rl_bind_key('\t', rl_menu_complete); @@ -86,18 +98,21 @@ abook_rl_init(int use_completion) rl_unbind_function_in_map(rl_menu_complete, rl_get_keymap()); } + rl_bind_key('g' & 31, rl_cancel); /* C-g */ + clear_history(); + + rl_cancelled = FALSE; } char * -abook_readline(WINDOW *w, int y, int x, char *s, int limit, int use_completion) +abook_readline(WINDOW *w, int y, int x, char *s, int limit, bool use_completion) { - char *ret = NULL; + char *ret; - rl_win = w; abook_rl_init(use_completion); - wmove(rl_win, rl_y = y, rl_x = x); + wmove(rl_win = w, rl_y = y, rl_x = x); rl_refresh(); if(s && *s) @@ -105,6 +120,12 @@ abook_readline(WINDOW *w, int y, int x, char *s, int limit, int use_completion) ret = readline(NULL); + if(rl_cancelled) { + if(ret) + free(ret); + ret = NULL; + } + return ret; } diff --git a/abook_rl.h b/abook_rl.h index d6c2c22..22b67ba 100644 --- a/abook_rl.h +++ b/abook_rl.h @@ -4,6 +4,6 @@ #include "abook_curses.h" char *abook_readline(WINDOW *w, int y, int x, char *s, int limit, - int use_completion); + bool use_completion); #endif diff --git a/edit.c b/edit.c index 90cc07d..9403975 100644 --- a/edit.c +++ b/edit.c @@ -187,6 +187,7 @@ change_field(char *msg, char **field) { int max_len = MAX_FIELD_LEN; char *old; + int ret = 0; if( !strncmp("E-mail", msg, 6) ) max_len = MAX_EMAIL_LEN; @@ -195,12 +196,19 @@ change_field(char *msg, char **field) *field = ui_readline(msg, old, max_len - 1, 0); - free(old); + if(*field) { + free(old); + if(!**field) + my_free(*field); + } else { + *field = old; + ret = 1; + } clear_statusline(); refresh_statusline(); - return 0; + return ret; } static void diff --git a/ui.c b/ui.c index b15d8ba..a7d1a54 100644 --- a/ui.c +++ b/ui.c @@ -239,7 +239,7 @@ statusline_addstr(char *str) } char * -ui_readline(char *prompt, char *s, int limit, int use_completion) +ui_readline(char *prompt, char *s, int limit, bool use_completion) { int y, x; char *ret; @@ -250,9 +250,6 @@ ui_readline(char *prompt, char *s, int limit, int use_completion) ret = abook_readline(bottom, y, x, s, limit, use_completion); - if(ret && !*ret) - my_free(ret); - if(ret) strtrim(ret); diff --git a/ui.h b/ui.h index da7cdfa..33107f8 100644 --- a/ui.h +++ b/ui.h @@ -20,7 +20,7 @@ int statusline_ask_boolean(char *msg, int def); void clear_statusline(); void display_help(int help); void statusline_addstr(char *str); -char * ui_readline(char *prompt, char *s, int limit, int use_completion); +char * ui_readline(char *prompt, char *s, int limit, bool use_completion); void refresh_statusline(); void get_commands(); void ui_remove_items();