From 2b11baa564e9b558cfc050b5f28505f37900f2c1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 31 Jan 2015 01:58:15 +0000 Subject: [PATCH] Added readline tab handler --- src/ui/inputwin.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index fe75bc61..649590bc 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -88,6 +88,32 @@ cb_linehandler(char *line) free(line); } +int +tab_handler(int count, int key) +{ + if (rl_point != rl_end) { + return 0; + } + + if ((strncmp(rl_line_buffer, "/", 1) != 0) && (ui_current_win_type() == WIN_MUC)) { + char *result = muc_autocomplete(rl_line_buffer); + if (result) { + rl_replace_line(result, 0); + rl_point = rl_end; + inp_write(result, rl_point); + } + } else if (strncmp(rl_line_buffer, "/", 1) == 0) { + char *result = cmd_autocomplete(rl_line_buffer); + if (result) { + rl_replace_line(result, 0); + rl_point = rl_end; + inp_write(result, rl_point); + } + } + + return 0; +} + void create_input_window(void) { @@ -99,7 +125,7 @@ create_input_window(void) p_rl_timeout.tv_sec = 0; p_rl_timeout.tv_usec = inp_timeout * 1000; rl_callback_handler_install(NULL, cb_linehandler); - + rl_bind_key('\t', tab_handler); inp_win = newpad(1, INP_WIN_MAX); wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));; keypad(inp_win, TRUE); @@ -205,6 +231,7 @@ inp_readline(void) } ui_reset_idle_time(); inp_nonblocking(TRUE); + rl_redisplay(); inp_write(rl_line_buffer, rl_point); } else { inp_nonblocking(FALSE);