mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added command autocomplete
This commit is contained in:
parent
467b5cce7e
commit
6bb120200e
2
Makefile
2
Makefile
@ -20,7 +20,7 @@ log.o: log.h
|
||||
windows.o: ui.h util.h contact_list.h preferences.h
|
||||
title_bar.o: ui.h
|
||||
status_bar.o: ui.h util.h
|
||||
input_win.o: ui.h preferences.h
|
||||
input_win.o: ui.h preferences.h util.h command.h
|
||||
jabber.o: jabber.h log.h ui.h contact_list.h
|
||||
profanity.o: log.h ui.h jabber.h command.h preferences.h \
|
||||
contact_list.h
|
||||
|
21
command.c
21
command.c
@ -32,6 +32,7 @@
|
||||
#include "ui.h"
|
||||
#include "util.h"
|
||||
#include "preferences.h"
|
||||
#include "prof_autocomplete.h"
|
||||
|
||||
static gboolean _handle_command(const char * const command,
|
||||
const char * const inp);
|
||||
@ -59,6 +60,8 @@ struct cmd_t {
|
||||
gboolean (*func)(const char * const inp);
|
||||
};
|
||||
|
||||
static PAutocomplete commands_ac;
|
||||
|
||||
static struct cmd_t commands[] = {
|
||||
{ "/away", _cmd_away },
|
||||
{ "/beep", _cmd_set_beep },
|
||||
@ -108,9 +111,27 @@ gboolean process_input(char *inp)
|
||||
|
||||
void command_init(void)
|
||||
{
|
||||
commands_ac = p_autocomplete_new();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < num_cmds; i++) {
|
||||
struct cmd_t *pcmd = commands+i;
|
||||
p_autocomplete_add(commands_ac, (gchar *)pcmd->cmd);
|
||||
}
|
||||
|
||||
history_init();
|
||||
}
|
||||
|
||||
char * cmd_complete(char *inp)
|
||||
{
|
||||
return p_autocomplete_complete(commands_ac, inp);
|
||||
}
|
||||
|
||||
void reset_command_completer(void)
|
||||
{
|
||||
p_autocomplete_reset(commands_ac);
|
||||
}
|
||||
|
||||
static gboolean _handle_command(const char * const command, const char * const inp)
|
||||
{
|
||||
int i;
|
||||
|
@ -25,5 +25,7 @@
|
||||
|
||||
void command_init(void);
|
||||
gboolean process_input(char *inp);
|
||||
char * cmd_complete(char *inp);
|
||||
void reset_command_completer(void);
|
||||
|
||||
#endif
|
||||
|
24
input_win.c
24
input_win.c
@ -44,6 +44,8 @@
|
||||
#include "ui.h"
|
||||
#include "history.h"
|
||||
#include "preferences.h"
|
||||
#include "util.h"
|
||||
#include "command.h"
|
||||
|
||||
static WINDOW *inp_win;
|
||||
|
||||
@ -124,6 +126,7 @@ void inp_get_char(int *ch, char *input, int *size)
|
||||
|
||||
reset_search_attempts();
|
||||
reset_login_search();
|
||||
reset_command_completer();
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +237,24 @@ static int _handle_edit(const int ch, char *input, int *size)
|
||||
return 1;
|
||||
|
||||
case 9: // tab
|
||||
if ((strncmp(input, "/msg ", 5) == 0) && (*size > 5)) {
|
||||
|
||||
// autocomplete commands
|
||||
if ((strncmp(input, "/", 1) == 0) && (!str_contains(input, *size, ' '))) {
|
||||
for(i = 0; i < *size; i++) {
|
||||
inp_cpy[i] = input[i];
|
||||
}
|
||||
inp_cpy[i] = '\0';
|
||||
found = cmd_complete(inp_cpy);
|
||||
if (found != NULL) {
|
||||
auto_msg = (char *) malloc((strlen(found) + 1) * sizeof(char));
|
||||
strcpy(auto_msg, found);
|
||||
_replace_input(input, auto_msg, size);
|
||||
free(auto_msg);
|
||||
free(found);
|
||||
}
|
||||
|
||||
// autcomplete /msg recipient
|
||||
} else if ((strncmp(input, "/msg ", 5) == 0) && (*size > 5)) {
|
||||
for(i = 5; i < *size; i++) {
|
||||
inp_cpy[i-5] = input[i];
|
||||
}
|
||||
@ -248,6 +268,8 @@ static int _handle_edit(const int ch, char *input, int *size)
|
||||
free(auto_msg);
|
||||
free(found);
|
||||
}
|
||||
|
||||
// autocomplete /connect username
|
||||
} else if ((strncmp(input, "/connect ", 9) == 0) && (*size > 9)) {
|
||||
for(i = 9; i < *size; i++) {
|
||||
inp_cpy[i-9] = input[i];
|
||||
|
11
util.c
11
util.c
@ -78,3 +78,14 @@ char * str_replace (const char *string, const char *substr,
|
||||
|
||||
return newstr;
|
||||
}
|
||||
|
||||
int str_contains(char str[], int size, char ch)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < size; i++) {
|
||||
if (str[i] == ch)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user