mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added /help parameter autocomplete
This commit is contained in:
parent
7d5d87ae39
commit
7a1c76fbb7
@ -54,9 +54,8 @@ struct cmd_t {
|
||||
static struct cmd_t * _cmd_get_command(const char * const command);
|
||||
static void _update_presence(const jabber_presence_t presence,
|
||||
const char * const show, const char * const inp);
|
||||
static gboolean
|
||||
_cmd_set_boolean_preference(const char * const inp, struct cmd_help_t help,
|
||||
const char * const cmd_str, const char * const display,
|
||||
static gboolean _cmd_set_boolean_preference(const char * const inp,
|
||||
struct cmd_help_t help, const char * const cmd_str, const char * const display,
|
||||
void (*set_func)(gboolean));
|
||||
|
||||
// command prototypes
|
||||
@ -353,6 +352,7 @@ static struct cmd_t status_commands[] =
|
||||
};
|
||||
|
||||
static PAutocomplete commands_ac;
|
||||
static PAutocomplete help_ac;
|
||||
|
||||
/*
|
||||
* Initialise command autocompleter and history
|
||||
@ -362,21 +362,25 @@ cmd_init(void)
|
||||
{
|
||||
log_info("Initialising commands");
|
||||
commands_ac = p_autocomplete_new();
|
||||
help_ac = p_autocomplete_new();
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; i < ARRAY_SIZE(main_commands); i++) {
|
||||
struct cmd_t *pcmd = main_commands+i;
|
||||
p_autocomplete_add(commands_ac, (gchar *)pcmd->cmd);
|
||||
p_autocomplete_add(help_ac, (gchar *)pcmd->cmd+1);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(setting_commands); i++) {
|
||||
struct cmd_t *pcmd = setting_commands+i;
|
||||
p_autocomplete_add(commands_ac, (gchar *)pcmd->cmd);
|
||||
p_autocomplete_add(help_ac, (gchar *)pcmd->cmd+1);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(status_commands); i++) {
|
||||
struct cmd_t *pcmd = status_commands+i;
|
||||
p_autocomplete_add(commands_ac, (gchar *)pcmd->cmd);
|
||||
p_autocomplete_add(help_ac, (gchar *)pcmd->cmd+1);
|
||||
}
|
||||
|
||||
history_init();
|
||||
@ -397,6 +401,17 @@ cmd_reset_completer(void)
|
||||
}
|
||||
|
||||
// Command help
|
||||
char *
|
||||
help_complete(char *inp)
|
||||
{
|
||||
return p_autocomplete_complete(help_ac, inp);
|
||||
}
|
||||
|
||||
void
|
||||
help_reset_completer(void)
|
||||
{
|
||||
p_autocomplete_reset(help_ac);
|
||||
}
|
||||
|
||||
GSList *
|
||||
cmd_get_basic_help(void)
|
||||
|
@ -39,6 +39,8 @@ gboolean cmd_execute(const char * const command, const char * const inp);
|
||||
gboolean cmd_execute_default(const char * const inp);
|
||||
|
||||
// command help
|
||||
char * help_complete(char *inp);
|
||||
void help_reset_completer(void);
|
||||
GSList * cmd_get_basic_help(void);
|
||||
GSList * cmd_get_settings_help(void);
|
||||
GSList * cmd_get_status_help(void);
|
||||
|
@ -162,6 +162,7 @@ inp_get_char(int *ch, char *input, int *size)
|
||||
|
||||
reset_search_attempts();
|
||||
reset_login_search();
|
||||
help_reset_completer();
|
||||
cmd_reset_completer();
|
||||
}
|
||||
}
|
||||
@ -365,6 +366,22 @@ _handle_edit(const int ch, char *input, int *size)
|
||||
free(auto_msg);
|
||||
free(found);
|
||||
}
|
||||
|
||||
// autocomplete /help command
|
||||
} else if ((strncmp(input, "/help ", 6) == 0) && (*size > 6)) {
|
||||
for(i = 6; i < *size; i++) {
|
||||
inp_cpy[i-6] = input[i];
|
||||
}
|
||||
inp_cpy[(*size) - 6] = '\0';
|
||||
found = help_complete(inp_cpy);
|
||||
if (found != NULL) {
|
||||
auto_msg = (char *) malloc((6 + (strlen(found) + 1)) * sizeof(char));
|
||||
strcpy(auto_msg, "/help ");
|
||||
strcat(auto_msg, found);
|
||||
_replace_input(input, auto_msg, size);
|
||||
free(auto_msg);
|
||||
free(found);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user