changeset 103:93dcc4e15d4a

[/trunk] Changeset 117 by mikael * Optimize scr_handle_tab() * Add /roster command completion (with its parameters) * Clean up compl.c (debug stuff) * Update TODO
author mikael
date Thu, 21 Apr 2005 19:38:23 +0000
parents 2b4cc6bc5bf2
children fe7257d251ac
files mcabber/src/TODO mcabber/src/commands.c mcabber/src/compl.c mcabber/src/compl.h mcabber/src/screen.c
diffstat 5 files changed, 47 insertions(+), 111 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/TODO	Thu Apr 21 19:06:27 2005 +0000
+++ b/mcabber/src/TODO	Thu Apr 21 19:38:23 2005 +0000
@@ -3,8 +3,6 @@
 
 * Should not stay on buddy buffer when one moves to a group
 * Pending message not displayed if buddy outside Contact window
-* Command not recognised if there is a trailing space! ("/quit ")
-* Completion is buggy when we're not at the EOL...
 
 
 TODO:
@@ -34,7 +32,6 @@
 * External commands for events
 * Multi-lines
 * Handle window resize
-* Command line completion
 * Scroll back history
 * Save history
 * Shortcut to jump to next message received (shift-tab?)
--- a/mcabber/src/commands.c	Thu Apr 21 19:06:27 2005 +0000
+++ b/mcabber/src/commands.c	Thu Apr 21 19:38:23 2005 +0000
@@ -62,6 +62,7 @@
   cmd_add("quit", "Exit the software", 0, 0, NULL);
   //cmd_add("rename");
   //cmd_add("request_auth");
+  cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, NULL);
   cmd_add("say", "Say something to the selected buddy", 0, 0, NULL);
   //cmd_add("search");
   //cmd_add("send_auth");
@@ -76,6 +77,12 @@
   compl_add_category_word(COMPL_STATUS, "busy");
   compl_add_category_word(COMPL_STATUS, "notavail");
   compl_add_category_word(COMPL_STATUS, "away");
+
+  // Roster category
+  compl_add_category_word(COMPL_ROSTER, "bottom");
+  compl_add_category_word(COMPL_ROSTER, "hide_offline");
+  compl_add_category_word(COMPL_ROSTER, "show_offline");
+  compl_add_category_word(COMPL_ROSTER, "top");
 }
 
 //  cmd_get
--- a/mcabber/src/compl.c	Thu Apr 21 19:06:27 2005 +0000
+++ b/mcabber/src/compl.c	Thu Apr 21 19:38:23 2005 +0000
@@ -170,42 +170,3 @@
   return NULL;
 }
 
-
-/*
-void test_dump_categories(void)
-{
-  GSList *sl_cat;
-  // Look for category
-  for (sl_cat=Categories; sl_cat; sl_cat = g_slist_next(sl_cat)) {
-    GSList *sl_words;
-    category *cat = (category*)sl_cat->data;
-    printf("Category: %u\n", cat->flag);
-    for (sl_words=cat->words; sl_words; sl_words = g_slist_next(sl_words)) {
-      char *word = sl_words->data;
-      printf("          Keyword: [%s]\n", word);
-    }
-  }
-}
-
-void test_comp(guint cat_flags, char *prefix)
-{
-  GSList *list = compl_get_category_list(cat_flags);
-  if (list) {
-    const char *cchar;
-    guint back;
-    int i;
-    new_completion(prefix, list);
-    cchar = complete();
-    printf("Complete -> \"%s\"\n", cchar);
-    for (i=0 ; i<5; i++) {
-    back = cancel_completion();
-    printf("Back: %d\n", back);
-    cchar = complete();
-    printf("Complete -> \"%s\"\n", cchar);
-    }
-    back = cancel_completion();
-    printf("Back: %d\n", back);
-    done_completion();
-  }
-}
-*/
--- a/mcabber/src/compl.h	Thu Apr 21 19:06:27 2005 +0000
+++ b/mcabber/src/compl.h	Thu Apr 21 19:38:23 2005 +0000
@@ -3,12 +3,13 @@
 
 #include <glib.h>
 
-#define COMPL_CMD        1      // Not implemented yet
+#define COMPL_CMD        1
 #define COMPL_JID        2      // Not implemented yet
 #define COMPL_URLJID     4      // Not implemented yet
 #define COMPL_NAME       8      // Not implemented yet
-#define COMPL_STATUS    16      // Not implemented yet
+#define COMPL_STATUS    16
 #define COMPL_FILENAME  32      // Not implemented yet
+#define COMPL_ROSTER    64
 
 void    compl_add_category_word(guint, const char *command);
 GSList *compl_get_category_list(guint cat_flags);
--- a/mcabber/src/screen.c	Thu Apr 21 19:06:27 2005 +0000
+++ b/mcabber/src/screen.c	Thu Apr 21 19:38:23 2005 +0000
@@ -634,84 +634,54 @@
 void scr_handle_tab(void)
 {
   int nrow;
-  cmd *com;
   char *row;
   const char *cchar;
+  guint compl_categ;
 
   nrow = which_row(&row);
 
-  if (nrow == -1) return;   // No completion if no leading slash
+  // a) No completion if no leading slash ('cause not a command)
+  // b) We can't have more than 2 parameters (we use 2 flags)
+  if (nrow < 0 || nrow > 2) return;
 
-  if (nrow == 0) {          // Command completion
-    if (!completion_started) {
-      GSList *list = compl_get_category_list(COMPL_CMD);
-      if (list) {
-        char *prefix = g_strndup(&inputLine[1], ptr_inputline-inputLine-1);
-        // Init completion
-        new_completion(prefix, list);
-        g_free(prefix);
-        // Now complete
-        cchar = complete();
-        if (cchar)
-          scr_insert_text(cchar);
-        completion_started = TRUE;
-      }
-    } else {    // Completion already initialized
-      char *c;
-      guint back = cancel_completion();
-      // Remove $back chars
-      ptr_inputline -= back;
-      c = ptr_inputline;
-      for ( ; *c ; c++)
-        *c = *(c+back);
-      // Now complete again
+  if (nrow == 0) {      // Command completion
+    row = &inputLine[1];
+    compl_categ = COMPL_CMD;
+  } else {              // Other completion, depending on the command
+    cmd *com = cmd_get(inputLine);
+    if (!com || !row) {
+      scr_LogPrint("I cannot complete that...");
+      return;
+    }
+    compl_categ = com->completion_flags[nrow-1];
+  }
+
+  if (!completion_started) {
+    GSList *list = compl_get_category_list(compl_categ);
+    if (list) {
+      char *prefix = g_strndup(row, ptr_inputline-row);
+      // Init completion
+      new_completion(prefix, list);
+      g_free(prefix);
+      // Now complete
       cchar = complete();
       if (cchar)
         scr_insert_text(cchar);
+      completion_started = TRUE;
     }
-    return;
-  }
-
-  // Other completion, depending on the command
-  com = cmd_get(inputLine);
-  if (!com) {
-    scr_LogPrint("I cannot complete for this command");
-    return;
+  } else {      // Completion already initialized
+    char *c;
+    guint back = cancel_completion();
+    // Remove $back chars
+    ptr_inputline -= back;
+    c = ptr_inputline;
+    for ( ; *c ; c++)
+      *c = *(c+back);
+    // Now complete again
+    cchar = complete();
+    if (cchar)
+      scr_insert_text(cchar);
   }
-  // Now we have the command and the column.
-  scr_LogPrint("CMD_FLAGR1=%d COL=%d row=[%s]", com->completion_flags[0], nrow, row);
-
-  // We can't have more than 2 parameters (we use 2 flags)
-  if (nrow > 2)
-    return;
-
-  // Dirty copy & paste
-    if (!completion_started) {
-      GSList *list = compl_get_category_list(com->completion_flags[nrow-1]);
-      if (list) {
-        char *prefix = g_strndup(row, ptr_inputline-row);
-        // Init completion
-        new_completion(prefix, list);
-        g_free(prefix);
-        // Now complete
-        cchar = complete();
-        if (cchar)
-          scr_insert_text(cchar);
-        completion_started = TRUE;
-      }
-    } else {    // Completion already initialized
-      char *c;
-      guint back = cancel_completion();
-      // Remove $back chars
-      ptr_inputline -= back;
-      c = ptr_inputline;
-      for ( ; *c ; c++)
-        *c = *(c+back);
-      // Now complete again
-      cchar = complete();
-      if (cchar)
-        scr_insert_text(cchar);
-    }
 }
 
 void scr_cancel_current_completion(void)