about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-17 22:21:12 +0100
committerJames Booth <boothj5@gmail.com>2014-09-17 22:21:12 +0100
commit9bfc499078adb040f27fb7e9bdfcd878e9e173d2 (patch)
treebe444bf8a331f64c138b590dcc7b83fe9f8c1847 /src/command
parentd2a06ab18e75723bd93a5db57c9c29c5db875d7c (diff)
downloadprofani-tty-9bfc499078adb040f27fb7e9bdfcd878e9e173d2.tar.gz
Added autocompletion for form boolean values
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c67
1 files changed, 51 insertions, 16 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 6e233238..0e6a6156 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -2097,34 +2097,69 @@ _theme_autocomplete(char *input, int *size)
 static char *
 _form_autocomplete(char *input, int *size)
 {
-    char *result = NULL;
+    char *found = NULL;
 
     ProfWin *current = wins_get_current();
     if (current != NULL) {
         DataForm *form = current->form;
         if (form != NULL) {
-            result = autocomplete_param_with_ac(input, size, "/form set", form->tag_ac, TRUE);
-            if (result != NULL) {
-                return result;
+            gboolean result = FALSE;
+
+            input[*size] = '\0';
+            gchar **args = parse_args(input, 3, 3, &result);
+
+            if ((strncmp(input, "/form", 5) == 0) && (result == TRUE)) {
+                char *cmd = args[0];
+                char *tag = args[1];
+
+                GString *beginning = g_string_new("/form ");
+                g_string_append(beginning, cmd);
+                g_string_append(beginning, " ");
+                g_string_append(beginning, tag);
+
+                form_field_type_t field_type = form_get_field_type(form, tag);
+
+                // handle boolean (set)
+                if ((g_strcmp0(args[0], "set") == 0)  && field_type == FIELD_BOOLEAN) {
+                    found = autocomplete_param_with_func(input, size, beginning->str,
+                        prefs_autocomplete_boolean_choice);
+                    g_string_free(beginning, TRUE);
+                    if (found != NULL) {
+                        return found;
+                    }
+                }
+
+                // handle list-single (set)
+
+                // handle list-multi (add, remove)
+
+                // handle text-multi (remove)
+
+                // handle jid-multi (remove)
             }
-            result = autocomplete_param_with_ac(input, size, "/form add", form->tag_ac, TRUE);
-            if (result != NULL) {
-                return result;
+
+            found = autocomplete_param_with_ac(input, size, "/form set", form->tag_ac, TRUE);
+            if (found != NULL) {
+                return found;
             }
-            result = autocomplete_param_with_ac(input, size, "/form remove", form->tag_ac, TRUE);
-            if (result != NULL) {
-                return result;
+            found = autocomplete_param_with_ac(input, size, "/form add", form->tag_ac, TRUE);
+            if (found != NULL) {
+                return found;
             }
-            result = autocomplete_param_with_ac(input, size, "/form help", form->tag_ac, TRUE);
-            if (result != NULL) {
-                return result;
+            found = autocomplete_param_with_ac(input, size, "/form remove", form->tag_ac, TRUE);
+            if (found != NULL) {
+                return found;
+            }
+            found = autocomplete_param_with_ac(input, size, "/form help", form->tag_ac, TRUE);
+            if (found != NULL) {
+                return found;
             }
         }
     }
 
-    result = autocomplete_param_with_ac(input, size, "/form", form_ac, TRUE);
-    if (result != NULL) {
-        return result;
+    found = autocomplete_param_with_ac(input, size, "/form", form_ac, TRUE);
+    if (found != NULL) {
+        return found;
     }
 
     return NULL;