0
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-07-26 12:14:28 -04:00

Integrated plugins with /help command

This commit is contained in:
James Booth 2016-02-18 21:53:20 +00:00
parent a152d7fb8e
commit 0ed3b53bd2
5 changed files with 53 additions and 11 deletions

View File

@ -127,6 +127,7 @@ GHashTable *commands = NULL;
#define CMD_TAG_CONNECTION "connection" #define CMD_TAG_CONNECTION "connection"
#define CMD_TAG_DISCOVERY "discovery" #define CMD_TAG_DISCOVERY "discovery"
#define CMD_TAG_UI "ui" #define CMD_TAG_UI "ui"
#define CMD_TAG_PLUGINS "plugins"
#define CMD_NOTAGS { { NULL }, #define CMD_NOTAGS { { NULL },
#define CMD_TAGS(...) { { __VA_ARGS__, NULL }, #define CMD_TAGS(...) { { __VA_ARGS__, NULL },
@ -2065,6 +2066,7 @@ cmd_init(void)
autocomplete_add(help_commands_ac, "discovery"); autocomplete_add(help_commands_ac, "discovery");
autocomplete_add(help_commands_ac, "connection"); autocomplete_add(help_commands_ac, "connection");
autocomplete_add(help_commands_ac, "ui"); autocomplete_add(help_commands_ac, "ui");
autocomplete_add(help_commands_ac, "plugins");
prefs_ac = autocomplete_new(); prefs_ac = autocomplete_new();
autocomplete_add(prefs_ac, "ui"); autocomplete_add(prefs_ac, "ui");
@ -2899,7 +2901,8 @@ cmd_valid_tag(const char *const str)
(g_strcmp0(str, CMD_TAG_ROSTER) == 0) || (g_strcmp0(str, CMD_TAG_ROSTER) == 0) ||
(g_strcmp0(str, CMD_TAG_DISCOVERY) == 0) || (g_strcmp0(str, CMD_TAG_DISCOVERY) == 0) ||
(g_strcmp0(str, CMD_TAG_CONNECTION) == 0) || (g_strcmp0(str, CMD_TAG_CONNECTION) == 0) ||
(g_strcmp0(str, CMD_TAG_UI) == 0)); (g_strcmp0(str, CMD_TAG_UI) == 0) ||
(g_strcmp0(str, CMD_TAG_PLUGINS) == 0));
} }
gboolean gboolean

View File

@ -1293,19 +1293,41 @@ _cmd_help_cmd_list(const char *const tag)
} }
GList *ordered_commands = NULL; GList *ordered_commands = NULL;
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init(&iter, commands); if (g_strcmp0(tag, "plugins") == 0) {
while (g_hash_table_iter_next(&iter, &key, &value)) { GList *plugins_cmds = plugins_get_command_names();
Command *pcmd = (Command *)value; GList *curr = plugins_cmds;
if (tag) { while (curr) {
if (cmd_has_tag(pcmd, tag)) { ordered_commands = g_list_insert_sorted(ordered_commands, curr->data, (GCompareFunc)g_strcmp0);
curr = g_list_next(curr);
}
g_list_free(plugins_cmds);
} else {
GHashTableIter iter;
gpointer key;
gpointer value;
g_hash_table_iter_init(&iter, commands);
while (g_hash_table_iter_next(&iter, &key, &value)) {
Command *pcmd = (Command *)value;
if (tag) {
if (cmd_has_tag(pcmd, tag)) {
ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0);
}
} else {
ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0);
} }
} else { }
ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0);
// add plugins if showing all commands
if (!tag) {
GList *plugins_cmds = plugins_get_command_names();
GList *curr = plugins_cmds;
while (curr) {
ordered_commands = g_list_insert_sorted(ordered_commands, curr->data, (GCompareFunc)g_strcmp0);
curr = g_list_next(curr);
}
g_list_free(plugins_cmds);
} }
} }

View File

@ -143,3 +143,18 @@ plugins_run_timed(void)
} }
return; return;
} }
GList*
plugins_get_command_names(void)
{
GList *result = NULL;
GSList *curr = p_commands;
while (curr) {
PluginCommand *command = curr->data;
result = g_list_append(result, (char*)command->command_name);
curr = g_slist_next(curr);
}
return result;
}

View File

@ -101,6 +101,7 @@ void plugins_post_priv_message_send(const char * const jid, const char * const
gboolean plugins_run_command(const char * const cmd); gboolean plugins_run_command(const char * const cmd);
void plugins_run_timed(void); void plugins_run_timed(void);
GList* plugins_get_command_names(void);
gchar * plugins_get_dir(void); gchar * plugins_get_dir(void);
CommandHelp* plugins_get_help(const char *const cmd); CommandHelp* plugins_get_help(const char *const cmd);

View File

@ -2050,6 +2050,7 @@ cons_help(void)
cons_show_padded(pad, "/help commands discovery : List service discovery commands."); cons_show_padded(pad, "/help commands discovery : List service discovery commands.");
cons_show_padded(pad, "/help commands connection : List commands related to managing your connection."); cons_show_padded(pad, "/help commands connection : List commands related to managing your connection.");
cons_show_padded(pad, "/help commands ui : List commands for manipulating the user interface."); cons_show_padded(pad, "/help commands ui : List commands for manipulating the user interface.");
cons_show_padded(pad, "/help commands plugins : List plugin commands.");
cons_show_padded(pad, "/help [command] : Detailed help on a specific command."); cons_show_padded(pad, "/help [command] : Detailed help on a specific command.");
cons_show_padded(pad, "/help navigation : How to navigate around Profanity."); cons_show_padded(pad, "/help navigation : How to navigate around Profanity.");
cons_show(""); cons_show("");