1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Autocomplete /group add and /group remove contact paramater

closes #193
This commit is contained in:
James Booth 2013-06-23 01:23:44 +01:00
parent 1cf20b2491
commit f9b8da1afe
3 changed files with 67 additions and 0 deletions

View File

@ -3547,6 +3547,15 @@ _group_autocomplete(char *input, int *size)
if (result != NULL) { if (result != NULL) {
return result; return result;
} }
result = autocomplete_param_no_with_func(input, size, "/group add", 4, roster_find_contact);
if (result != NULL) {
return result;
}
result = autocomplete_param_no_with_func(input, size, "/group remove", 4, roster_find_contact);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_func(input, size, "/group add", roster_find_group); result = autocomplete_param_with_func(input, size, "/group add", roster_find_group);
if (result != NULL) { if (result != NULL) {
return result; return result;

View File

@ -260,6 +260,62 @@ autocomplete_param_with_ac(char *input, int *size, char *command,
return auto_msg; return auto_msg;
} }
char *
autocomplete_param_no_with_func(char *input, int *size, char *command,
int arg_number, autocomplete_func func)
{
char *result = NULL;
if (strncmp(input, command, strlen(command)) == 0 && (*size > strlen(command))) {
int i = 0;
int quote_count = 0;
char *found = NULL;
GString *result_str = NULL;
// copy and null terminate input, count quotes
gchar inp_cpy[*size];
for (i = 0; i < *size; i++) {
if (input[i] == '"') {
quote_count++;
}
inp_cpy[i] = input[i];
}
inp_cpy[i] = '\0';
g_strstrip(inp_cpy);
// count tokens
gchar **tokens = g_strsplit(inp_cpy, " ", 0);
int num_tokens = g_strv_length(tokens);
// if num tokens, or 2 quotes then candidate for autocompletion of last param
if (((num_tokens > arg_number - 1) && quote_count == 0) || quote_count == 2) {
gchar *comp_str = NULL;
// find start of autocompletion string
if (num_tokens > 3 && quote_count == 0) {
comp_str = g_strrstr(inp_cpy, tokens[arg_number - 1]);
} else {
comp_str = g_strrstr(inp_cpy, "\"");
comp_str = comp_str + 2;
}
// autocomplete param
if (comp_str != NULL) {
found = func(comp_str);
if (found != NULL) {
result_str = g_string_new("");
g_string_append(result_str, g_strndup(inp_cpy, strlen(inp_cpy) - strlen(comp_str)));
g_string_append(result_str, found);
result = result_str->str;
g_string_free(result_str, FALSE);
return result;
}
}
}
}
return NULL;
}
static gchar * static gchar *
_search_from(Autocomplete ac, GSList *curr) _search_from(Autocomplete ac, GSList *curr)

View File

@ -47,5 +47,7 @@ char * autocomplete_param_with_func(char *input, int *size, char *command,
autocomplete_func func); autocomplete_func func);
char * autocomplete_param_with_ac(char *input, int *size, char *command, char * autocomplete_param_with_ac(char *input, int *size, char *command,
Autocomplete ac); Autocomplete ac);
char * autocomplete_param_no_with_func(char *input, int *size, char *command,
int arg_number, autocomplete_func func);
#endif #endif