4 * by JH <jheinonen@users.sourceforge.net>
6 * Copyright (C) Jaakko Heinonen
11 #include <sys/types.h>
19 #if defined(HAVE_READLINE_READLINE_H)
20 # include <readline/readline.h>
21 #elif defined(HAVE_READLINE_H)
22 # include <readline.h>
25 #if defined(HAVE_READLINE_HISTORY_H)
26 # include <readline/history.h>
27 #elif defined(HAVE_HISTORY_H)
31 #define RL_READLINE_NAME "Abook"
33 static int rl_x, rl_y;
34 static WINDOW *rl_win;
36 static bool rl_cancelled;
48 int real_point = rl_point + rl_x;
50 if(real_point > (COLS - 1))
51 mvwaddnstr(rl_win, rl_y, rl_x,
52 rl_line_buffer + (1 + real_point - COLS),
55 mvwaddnstr(rl_win, rl_y, rl_x, rl_line_buffer, rl_end);
58 wmove(rl_win, rl_y, min(real_point, COLS - 1));
64 rline_compdisp(char **matches, int n, int max_len)
70 rl_cancel(int dummy1, int dummy2)
80 abook_rl_init(bool use_completion)
82 rl_readline_name = RL_READLINE_NAME;
84 rl_already_prompted = 1;
85 rl_catch_sigwinch = 0;
87 rl_redisplay_function = rline_update;
88 rl_completion_display_matches_hook = rline_compdisp;
90 rl_unbind_function_in_map(rl_clear_screen, rl_get_keymap());
91 rl_unbind_function_in_map(rl_reverse_search_history, rl_get_keymap());
92 rl_unbind_function_in_map(rl_re_read_init_file, rl_get_keymap());
95 rl_bind_key('\t', rl_menu_complete);
97 rl_unbind_function_in_map(rl_complete, rl_get_keymap());
98 rl_unbind_function_in_map(rl_menu_complete, rl_get_keymap());
101 rl_bind_key('g' & 31, rl_cancel); /* C-g */
105 rl_cancelled = FALSE;
109 abook_readline(WINDOW *w, int y, int x, char *s, int limit, bool use_completion)
113 abook_rl_init(use_completion);
115 wmove(rl_win = w, rl_y = y, rl_x = x);
121 ret = readline(NULL);
123 if(rl_cancelled && ret) {