about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-06-30 23:14:05 +0100
committerJames Booth <boothj5@gmail.com>2016-06-30 23:14:05 +0100
commitef6bad483eef8f83393623127e1a27a46fa8b221 (patch)
treee4397de79130f2be53d347f7eec957d917cb0169 /src/command
parent56480ce9ea25697215e677d029f0ad25f9cc8b99 (diff)
downloadprofani-tty-ef6bad483eef8f83393623127e1a27a46fa8b221.tar.gz
/plugins unload command and completer
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_ac.c27
-rw-r--r--src/command/cmd_defs.c7
-rw-r--r--src/command/cmd_funcs.c14
3 files changed, 46 insertions, 2 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 1dfc5cc0..a4cd788e 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -185,6 +185,7 @@ static Autocomplete console_msg_ac;
 static Autocomplete autoping_ac;
 static Autocomplete plugins_ac;
 static Autocomplete plugins_load_ac;
+static Autocomplete plugins_unload_ac;
 static Autocomplete sendfile_ac;
 static Autocomplete blocked_ac;
 static Autocomplete tray_ac;
@@ -484,6 +485,7 @@ cmd_ac_init(void)
 
     theme_load_ac = NULL;
     plugins_load_ac = NULL;
+    plugins_unload_ac = NULL;
 
     who_roster_ac = autocomplete_new();
     autocomplete_add(who_roster_ac, "chat");
@@ -702,6 +704,7 @@ cmd_ac_init(void)
 
     plugins_ac = autocomplete_new();
     autocomplete_add(plugins_ac, "load");
+    autocomplete_add(plugins_ac, "unload");
 
     sendfile_ac = autocomplete_new();
 
@@ -909,6 +912,10 @@ cmd_ac_reset(ProfWin *window)
         autocomplete_free(plugins_load_ac);
         plugins_load_ac = NULL;
     }
+    if (plugins_unload_ac) {
+        autocomplete_free(plugins_unload_ac);
+        plugins_unload_ac = NULL;
+    }
     autocomplete_reset(account_ac);
     autocomplete_reset(account_set_ac);
     autocomplete_reset(account_clear_ac);
@@ -1087,6 +1094,7 @@ cmd_ac_uninit(void)
     autocomplete_free(autoping_ac);
     autocomplete_free(plugins_ac);
     autocomplete_free(plugins_load_ac);
+    autocomplete_free(plugins_unload_ac);
     autocomplete_free(sendfile_ac);
     autocomplete_free(blocked_ac);
     autocomplete_free(tray_ac);
@@ -1865,6 +1873,7 @@ static char*
 _plugins_autocomplete(ProfWin *window, const char *const input)
 {
     char *result = NULL;
+
     if (strncmp(input, "/plugins load ", 14) == 0) {
         if (plugins_load_ac == NULL) {
             plugins_load_ac = autocomplete_new();
@@ -1881,6 +1890,24 @@ _plugins_autocomplete(ProfWin *window, const char *const input)
             return result;
         }
     }
+
+    if (strncmp(input, "/plugins unload ", 16) == 0) {
+        if (plugins_unload_ac == NULL) {
+            plugins_unload_ac = autocomplete_new();
+            GSList *plugins = plugins_loaded_list();
+            GSList *curr = plugins;
+            while (curr) {
+                autocomplete_add(plugins_unload_ac, curr->data);
+                curr = g_slist_next(curr);
+            }
+            g_slist_free(plugins);
+        }
+        result = autocomplete_param_with_ac(input, "/plugins unload", plugins_unload_ac, TRUE);
+        if (result) {
+            return result;
+        }
+    }
+
     result = autocomplete_param_with_ac(input, "/plugins", plugins_ac, TRUE);
     if (result) {
         return result;
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index dacf1c91..02f5ee93 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -1979,13 +1979,16 @@ static struct cmd_t command_defs[] =
         CMD_NOTAGS
         CMD_SYN(
             "/plugins",
+            "/plugins unload <plugin>",
             "/plugins load <plugin>")
         CMD_DESC(
             "Manage plugins. Passing no arguments lists currently loaded plugins.")
         CMD_ARGS(
-            { "load <plugin>",       "Load a plugin." })
+            { "load <plugin>",       "Load a plugin." },
+            { "unload <plugin>",     "Unload a plugin." })
         CMD_EXAMPLES(
-            "/plugin load browser.py")
+            "/plugin load browser.py",
+            "/plugin unload say.py")
     },
 
     { "/prefs",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 7f3419e3..b935f13d 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -6039,6 +6039,20 @@ cmd_plugins(ProfWin *window, const char *const command, gchar **args)
         }
 
         return TRUE;
+    } else if (g_strcmp0(args[0], "unload") == 0) {
+        if (args[1] == NULL) {
+            cons_bad_cmd_usage(command);
+            return TRUE;
+        }
+        gboolean res = plugins_unload(args[1]);
+        if (res) {
+            prefs_remove_plugin(args[1]);
+            cons_show("Unloaded plugin: %s", args[1]);
+        } else {
+            cons_show("Failed to unload plugin: %s", args[1]);
+        }
+
+        return TRUE;
     } else {
         GSList *plugins = plugins_get_list();
         GSList *curr = plugins;