1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Added aliases to autocomplete

This commit is contained in:
James Booth 2014-01-23 23:53:20 +00:00
parent 66631308a5
commit 5d85974bc0
6 changed files with 41 additions and 9 deletions

View File

@ -547,7 +547,7 @@ static struct cmd_t command_defs[] =
NULL } } },
{ "/alias",
cmd_alias, parse_args_with_freetext, 1, 3, &cons_alias_setting,
cmd_alias, parse_args_with_freetext, 1, 3, NULL,
{ "/alias add|remove|list [name value]", "Add your own command aliases.",
{ "/alias add|remove|list [name value]",
"-----------------------------------",
@ -907,6 +907,18 @@ cmd_init(void)
autocomplete_add(help_ac, pcmd->cmd+1);
}
// load aliases
GList *aliases = prefs_get_aliases();
GList *curr = aliases;
while (curr != NULL) {
ProfAlias *alias = curr->data;
GString *ac_alias = g_string_new("/");
g_string_append(ac_alias, alias->name);
autocomplete_add(commands_ac, ac_alias->str);
g_string_free(ac_alias, TRUE);
curr = g_list_next(curr);
}
prefs_ac = autocomplete_new();
autocomplete_add(prefs_ac, "ui");
autocomplete_add(prefs_ac, "desktop");
@ -1096,6 +1108,22 @@ cmd_uninit(void)
autocomplete_free(alias_ac);
}
void
cmd_autocomplete_add(char *value)
{
if (commands_ac != NULL) {
autocomplete_add(commands_ac, value);
}
}
void
cmd_autocomplete_remove(char *value)
{
if (commands_ac != NULL) {
autocomplete_remove(commands_ac, value);
}
}
// Command autocompletion functions
void
cmd_autocomplete(char *input, int *size)

View File

@ -32,6 +32,8 @@ void cmd_uninit(void);
void cmd_autocomplete(char *input, int *size);
void cmd_reset_autocomplete(void);
void cmd_autocomplete_add(char *value);
void cmd_autocomplete_remove(char *value);
gboolean cmd_execute(const char * const command, const char * const inp);
gboolean cmd_execute_alias(const char * const inp, gboolean *ran);

View File

@ -27,6 +27,7 @@
#include "chat_session.h"
#include "command/commands.h"
#include "command/command.h"
#include "common.h"
#include "config/accounts.h"
#include "config/account.h"
@ -1835,6 +1836,10 @@ cmd_alias(gchar **args, struct cmd_help_t help)
return TRUE;
} else {
if (prefs_add_alias(alias, value) == TRUE) {
GString *ac_value = g_string_new("/");
g_string_append(ac_value, alias);
cmd_autocomplete_add(ac_value->str);
g_string_free(ac_value, TRUE);
cons_show("Command alias added /%s -> %s", alias, value);
} else {
cons_show("Command alias /%s already exists.", alias);
@ -1852,6 +1857,10 @@ cmd_alias(gchar **args, struct cmd_help_t help)
if (!removed) {
cons_show("No such command alias /%s", alias);
} else {
GString *ac_value = g_string_new("/");
g_string_append(ac_value, alias);
cmd_autocomplete_remove(ac_value->str);
g_string_free(ac_value, TRUE);
cons_show("Command alias removed -> /%s", alias);
}
return TRUE;

View File

@ -917,12 +917,6 @@ _cons_show_aliases(GList *aliases)
cons_show("");
}
static void
_cons_alias_setting(void)
{
cons_show("Alias setting TODO");
}
static void
_cons_theme_setting(void)
{
@ -1628,7 +1622,6 @@ console_init_module(void)
cons_mouse_setting = _cons_mouse_setting;
cons_statuses_setting = _cons_statuses_setting;
cons_titlebar_setting = _cons_titlebar_setting;
cons_alias_setting = _cons_alias_setting;
cons_show_ui_prefs = _cons_show_ui_prefs;
cons_notify_setting = _cons_notify_setting;
cons_show_desktop_prefs = _cons_show_desktop_prefs;

View File

@ -203,7 +203,6 @@ void (*cons_show_received_subs)(void);
void (*cons_show_sent_subs)(void);
void (*cons_alert)(void);
void (*cons_theme_setting)(void);
void (*cons_alias_setting)(void);
void (*cons_beep_setting)(void);
void (*cons_flash_setting)(void);
void (*cons_splash_setting)(void);

View File

@ -14,6 +14,7 @@
#include "config/preferences.h"
#include "command/command.h"
#include "command/commands.h"
void cmd_alias_add_shows_usage_when_no_args(void **state)