static int rl_x, rl_y;
static WINDOW *rl_win;
+static bool rl_cancelled;
+
static void
rl_refresh()
{
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);
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)
ret = readline(NULL);
+ if(rl_cancelled) {
+ if(ret)
+ free(ret);
+ ret = NULL;
+ }
+
return ret;
}
{
int max_len = MAX_FIELD_LEN;
char *old;
+ int ret = 0;
if( !strncmp("E-mail", msg, 6) )
max_len = MAX_EMAIL_LEN;
*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
}
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;
ret = abook_readline(bottom, y, x, s, limit, use_completion);
- if(ret && !*ret)
- my_free(ret);
-
if(ret)
strtrim(ret);
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();