about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2017-04-01 00:27:11 +0100
committerJames Booth <boothj5@gmail.com>2017-04-01 00:27:11 +0100
commit6b830277a6e2f90c7f8fde94ccf31dc6a4e4e73e (patch)
tree4b99ba6b6d48c51bce6dfa6f8dbb30e1f4501832 /src/ui
parent1b9d033cef78365ca73ac504041ce129fdf334d2 (diff)
downloadprofani-tty-6b830277a6e2f90c7f8fde94ccf31dc6a4e4e73e.tar.gz
Allow previous autocompletion with shift tab
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/console.c12
-rw-r--r--src/ui/inputwin.c51
-rw-r--r--src/ui/rosterwin.c8
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/window_list.c8
-rw-r--r--src/ui/window_list.h4
6 files changed, 66 insertions, 19 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index 4c24b450..3b904c62 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -505,7 +505,7 @@ cons_show_wins(gboolean unread)
 }
 
 void
-cons_show_room_invites(GSList *invites)
+cons_show_room_invites(GList *invites)
 {
     cons_show("");
     if (invites == NULL) {
@@ -514,7 +514,7 @@ cons_show_room_invites(GSList *invites)
         cons_show("Chat room invites, use /join or /decline commands:");
         while (invites) {
             cons_show("  %s", invites->data);
-            invites = g_slist_next(invites);
+            invites = g_list_next(invites);
         }
     }
 
@@ -608,17 +608,17 @@ cons_show_caps(const char *const fulljid, resource_presence_t presence)
 void
 cons_show_received_subs(void)
 {
-    GSList *received = presence_get_subscription_requests();
+    GList *received = presence_get_subscription_requests();
     if (received == NULL) {
         cons_show("No outstanding subscription requests.");
     } else {
         cons_show("Outstanding subscription requests from:",
-            g_slist_length(received));
+            g_list_length(received));
         while (received) {
             cons_show("  %s", received->data);
-            received = g_slist_next(received);
+            received = g_list_next(received);
         }
-        g_slist_free_full(received, g_free);
+        g_list_free_full(received, g_free);
     }
 
     cons_alert();
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index b42c366a..e4da800b 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -96,6 +96,7 @@ static void _inp_rl_addfuncs(void);
 static int _inp_rl_getc(FILE *stream);
 static void _inp_rl_linehandler(char *line);
 static int _inp_rl_tab_handler(int count, int key);
+static int _inp_rl_shift_tab_handler(int count, int key);
 static int _inp_rl_win_clear_handler(int count, int key);
 static int _inp_rl_win_1_handler(int count, int key);
 static int _inp_rl_win_2_handler(int count, int key);
@@ -421,6 +422,7 @@ _inp_rl_startup_hook(void)
     rl_bind_keyseq("\\eOs", _inp_rl_win_pagedown_handler);
 
     rl_bind_key('\t', _inp_rl_tab_handler);
+    rl_bind_keyseq("\\e[Z", _inp_rl_shift_tab_handler);
 
     // unbind unwanted mappings
     rl_bind_keyseq("\\e=", NULL);
@@ -449,10 +451,27 @@ _inp_rl_linehandler(char *line)
     inp_line = line;
 }
 
+static gboolean shift_tab = FALSE;
+
 static int
 _inp_rl_getc(FILE *stream)
 {
     int ch = rl_getc(stream);
+
+    // 27, 91, 90 = Shift tab
+    if (ch == 27) {
+        shift_tab = TRUE;
+        return ch;
+    }
+    if (shift_tab && ch == 91) {
+        return ch;
+    }
+    if (shift_tab && ch == 90) {
+        return ch;
+    }
+
+    shift_tab = FALSE;
+
     if (_inp_printable(ch)) {
         ProfWin *window = wins_get_current();
         cmd_ac_reset(window);
@@ -477,7 +496,35 @@ _inp_rl_tab_handler(int count, int key)
 
     ProfWin *current = wins_get_current();
     if ((strncmp(rl_line_buffer, "/", 1) != 0) && (current->type == WIN_MUC)) {
-        char *result = muc_autocomplete(current, rl_line_buffer);
+        char *result = muc_autocomplete(current, rl_line_buffer, FALSE);
+        if (result) {
+            rl_replace_line(result, 1);
+            rl_point = rl_end;
+            free(result);
+        }
+    } else if (strncmp(rl_line_buffer, "/", 1) == 0) {
+        ProfWin *window = wins_get_current();
+        char *result = cmd_ac_complete(window, rl_line_buffer, FALSE);
+        if (result) {
+            rl_replace_line(result, 1);
+            rl_point = rl_end;
+            free(result);
+        }
+    }
+
+    return 0;
+}
+
+static int
+_inp_rl_shift_tab_handler(int count, int key)
+{
+    if (rl_point != rl_end || !rl_line_buffer) {
+        return 0;
+    }
+
+    ProfWin *current = wins_get_current();
+    if ((strncmp(rl_line_buffer, "/", 1) != 0) && (current->type == WIN_MUC)) {
+        char *result = muc_autocomplete(current, rl_line_buffer, TRUE);
         if (result) {
             rl_replace_line(result, 1);
             rl_point = rl_end;
@@ -485,7 +532,7 @@ _inp_rl_tab_handler(int count, int key)
         }
     } else if (strncmp(rl_line_buffer, "/", 1) == 0) {
         ProfWin *window = wins_get_current();
-        char *result = cmd_ac_complete(window, rl_line_buffer);
+        char *result = cmd_ac_complete(window, rl_line_buffer, TRUE);
         if (result) {
             rl_replace_line(result, 1);
             rl_point = rl_end;
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 30dedea6..bbeaba21 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -138,13 +138,13 @@ rosterwin_roster(void)
             _rosterwin_contacts_by_presence(layout, "dnd", "Do not disturb");
             _rosterwin_contacts_by_presence(layout, "offline", "Offline");
         } else if (g_strcmp0(by, "group") == 0) {
-            GSList *groups = roster_get_groups();
-            GSList *curr_group = groups;
+            GList *groups = roster_get_groups();
+            GList *curr_group = groups;
             while (curr_group) {
                 _rosterwin_contacts_by_group(layout, curr_group->data);
-                curr_group = g_slist_next(curr_group);
+                curr_group = g_list_next(curr_group);
             }
-            g_slist_free_full(groups, free);
+            g_list_free_full(groups, free);
             _rosterwin_contacts_by_group(layout, NULL);
         } else {
             _rosterwin_contacts_all(layout);
diff --git a/src/ui/ui.h b/src/ui/ui.h
index a04dc9e6..c2c6a969 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -278,7 +278,7 @@ void cons_show_incoming_room_message(const char *const nick, const char *const r
     gboolean mention, GList *triggers, int unread);
 void cons_show_incoming_message(const char *const short_from, const int win_index, int unread);
 void cons_show_incoming_private_message(const char *const nick, const char *const room, const int win_index, int unread);
-void cons_show_room_invites(GSList *invites);
+void cons_show_room_invites(GList *invites);
 void cons_show_received_subs(void);
 void cons_show_sent_subs(void);
 void cons_alert(void);
diff --git a/src/ui/window_list.c b/src/ui/window_list.c
index cf16dbab..2d19ab32 100644
--- a/src/ui/window_list.c
+++ b/src/ui/window_list.c
@@ -1073,15 +1073,15 @@ wins_create_summary(gboolean unread)
 }
 
 char*
-win_autocomplete(const char *const search_str)
+win_autocomplete(const char *const search_str, gboolean previous)
 {
-    return autocomplete_complete(wins_ac, search_str, TRUE);
+    return autocomplete_complete(wins_ac, search_str, TRUE, previous);
 }
 
 char*
-win_close_autocomplete(const char *const search_str)
+win_close_autocomplete(const char *const search_str, gboolean previous)
 {
-    return autocomplete_complete(wins_close_ac, search_str, TRUE);
+    return autocomplete_complete(wins_close_ac, search_str, TRUE, previous);
 }
 
 void
diff --git a/src/ui/window_list.h b/src/ui/window_list.h
index 450175b7..dc1f3be4 100644
--- a/src/ui/window_list.h
+++ b/src/ui/window_list.h
@@ -91,9 +91,9 @@ gboolean wins_swap(int source_win, int target_win);
 void wins_hide_subwin(ProfWin *window);
 void wins_show_subwin(ProfWin *window);
 
-char* win_autocomplete(const char *const search_str);
+char* win_autocomplete(const char *const search_str, gboolean previous);
 void win_reset_search_attempts(void);
-char* win_close_autocomplete(const char *const search_str);
+char* win_close_autocomplete(const char *const search_str, gboolean previous);
 void win_close_reset_search_attempts(void);
 
 #endif