about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-31 01:58:15 +0000
committerJames Booth <boothj5@gmail.com>2015-01-31 01:58:15 +0000
commit2b11baa564e9b558cfc050b5f28505f37900f2c1 (patch)
treef50907f761b3fb2e7ab54ce5f492b1eb65545360
parentb3448eb265c7b656c07d3a72ea498dc6b5c5b888 (diff)
downloadprofani-tty-2b11baa564e9b558cfc050b5f28505f37900f2c1.tar.gz
Added readline tab handler
-rw-r--r--src/ui/inputwin.c29
1 files changed, 28 insertions, 1 deletions
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);