about summary refs log tree commit diff stats
path: root/src/command.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-12-09 00:46:14 +0000
committerJames Booth <boothj5@gmail.com>2012-12-09 00:46:14 +0000
commita855709b5eee862b4bb0ffe28b16b277da2ff5ae (patch)
treedcc524016ca8b86d66e5b2edb782893e908689b0 /src/command.c
parent53ac41057c4c382a507a03aaeb589fd22eba83a1 (diff)
downloadprofani-tty-a855709b5eee862b4bb0ffe28b16b277da2ff5ae.tar.gz
Added autocomplete to /theme load
Diffstat (limited to 'src/command.c')
-rw-r--r--src/command.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/command.c b/src/command.c
index d6092940..e68a7b08 100644
--- a/src/command.c
+++ b/src/command.c
@@ -76,6 +76,7 @@ static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
 static void _cmd_complete_parameters(char *input, int *size);
 static void _notify_autocomplete(char *input, int *size);
 static void _titlebar_autocomplete(char *input, int *size);
+static void _theme_autocomplete(char *input, int *size);
 static void _autoaway_autocomplete(char *input, int *size);
 static void _parameter_autocomplete(char *input, int *size, char *command,
     autocomplete_func func);
@@ -638,6 +639,8 @@ static PAutocomplete log_ac;
 static PAutocomplete autoaway_ac;
 static PAutocomplete autoaway_mode_ac;
 static PAutocomplete titlebar_ac;
+static PAutocomplete theme_ac;
+static PAutocomplete theme_load_ac;
 
 /*
  * Initialise command autocompleter and history
@@ -695,6 +698,12 @@ cmd_init(void)
     p_autocomplete_add(autoaway_mode_ac, strdup("idle"));
     p_autocomplete_add(autoaway_mode_ac, strdup("off"));
 
+    theme_ac = p_autocomplete_new();
+    p_autocomplete_add(theme_ac, strdup("list"));
+    p_autocomplete_add(theme_ac, strdup("load"));
+
+    theme_load_ac = NULL;
+
     unsigned int i;
     for (i = 0; i < ARRAY_SIZE(main_commands); i++) {
         struct cmd_t *pcmd = main_commands+i;
@@ -734,6 +743,10 @@ cmd_close(void)
     p_autocomplete_clear(prefs_ac);
     p_autocomplete_clear(autoaway_ac);
     p_autocomplete_clear(autoaway_mode_ac);
+    p_autocomplete_clear(theme_ac);
+    if (theme_load_ac != NULL) {
+        p_autocomplete_clear(theme_load_ac);
+    }
 }
 
 // Command autocompletion functions
@@ -781,6 +794,11 @@ cmd_reset_autocomplete()
     p_autocomplete_reset(commands_ac);
     p_autocomplete_reset(autoaway_ac);
     p_autocomplete_reset(autoaway_mode_ac);
+    p_autocomplete_reset(theme_ac);
+    if (theme_load_ac != NULL) {
+        p_autocomplete_clear(theme_load_ac);
+        theme_load_ac = NULL;
+    }
 }
 
 GSList *
@@ -921,6 +939,7 @@ _cmd_complete_parameters(char *input, int *size)
     _notify_autocomplete(input, size);
     _autoaway_autocomplete(input, size);
     _titlebar_autocomplete(input, size);
+    _theme_autocomplete(input, size);
 }
 
 // The command functions
@@ -1236,7 +1255,9 @@ _cmd_theme(gchar **args, struct cmd_help_t help)
 
     // load a theme
     } else if (strcmp(args[0], "load") == 0) {
-        if (theme_load(args[1])) {
+        if (args[1] == NULL) {
+            cons_show("Usage: %s", help.usage);
+        } else if (theme_load(args[1])) {
             ui_load_colours();
             prefs_set_theme(args[1]);
             cons_show("Loaded theme: %s", args[1]);
@@ -2078,6 +2099,25 @@ _autoaway_autocomplete(char *input, int *size)
     }
 }
 
+static void
+_theme_autocomplete(char *input, int *size)
+{
+    if ((strncmp(input, "/theme load ", 12) == 0) && (*size > 12)) {
+        if (theme_load_ac == NULL) {
+            theme_load_ac = p_autocomplete_new();
+            GSList *themes = theme_list();
+            while (themes != NULL) {
+                p_autocomplete_add(theme_load_ac, strdup(themes->data));
+                themes = g_slist_next(themes);
+            }
+            g_slist_free(themes);
+         }
+        _parameter_autocomplete_with_ac(input, size, "/theme load", theme_load_ac);
+    } else if ((strncmp(input, "/theme ", 7) == 0) && (*size > 7)) {
+        _parameter_autocomplete_with_ac(input, size, "/theme", theme_ac);
+    }
+}
+
 static int
 _strtoi(char *str, int *saveptr, int min, int max)
 {