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
|
windows.o: ui.h util.h contact_list.h preferences.h
|
||||||
title_bar.o: ui.h
|
title_bar.o: ui.h
|
||||||
status_bar.o: ui.h util.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
|
jabber.o: jabber.h log.h ui.h contact_list.h
|
||||||
profanity.o: log.h ui.h jabber.h command.h preferences.h \
|
profanity.o: log.h ui.h jabber.h command.h preferences.h \
|
||||||
contact_list.h
|
contact_list.h
|
||||||
|
21
command.c
21
command.c
@ -32,6 +32,7 @@
|
|||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
#include "prof_autocomplete.h"
|
||||||
|
|
||||||
static gboolean _handle_command(const char * const command,
|
static gboolean _handle_command(const char * const command,
|
||||||
const char * const inp);
|
const char * const inp);
|
||||||
@ -59,6 +60,8 @@ struct cmd_t {
|
|||||||
gboolean (*func)(const char * const inp);
|
gboolean (*func)(const char * const inp);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static PAutocomplete commands_ac;
|
||||||
|
|
||||||
static struct cmd_t commands[] = {
|
static struct cmd_t commands[] = {
|
||||||
{ "/away", _cmd_away },
|
{ "/away", _cmd_away },
|
||||||
{ "/beep", _cmd_set_beep },
|
{ "/beep", _cmd_set_beep },
|
||||||
@ -108,9 +111,27 @@ gboolean process_input(char *inp)
|
|||||||
|
|
||||||
void command_init(void)
|
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();
|
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)
|
static gboolean _handle_command(const char * const command, const char * const inp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -25,5 +25,7 @@
|
|||||||
|
|
||||||
void command_init(void);
|
void command_init(void);
|
||||||
gboolean process_input(char *inp);
|
gboolean process_input(char *inp);
|
||||||
|
char * cmd_complete(char *inp);
|
||||||
|
void reset_command_completer(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
24
input_win.c
24
input_win.c
@ -44,6 +44,8 @@
|
|||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "history.h"
|
#include "history.h"
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "command.h"
|
||||||
|
|
||||||
static WINDOW *inp_win;
|
static WINDOW *inp_win;
|
||||||
|
|
||||||
@ -124,6 +126,7 @@ void inp_get_char(int *ch, char *input, int *size)
|
|||||||
|
|
||||||
reset_search_attempts();
|
reset_search_attempts();
|
||||||
reset_login_search();
|
reset_login_search();
|
||||||
|
reset_command_completer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +237,24 @@ static int _handle_edit(const int ch, char *input, int *size)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case 9: // tab
|
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++) {
|
for(i = 5; i < *size; i++) {
|
||||||
inp_cpy[i-5] = input[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(auto_msg);
|
||||||
free(found);
|
free(found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// autocomplete /connect username
|
||||||
} else if ((strncmp(input, "/connect ", 9) == 0) && (*size > 9)) {
|
} else if ((strncmp(input, "/connect ", 9) == 0) && (*size > 9)) {
|
||||||
for(i = 9; i < *size; i++) {
|
for(i = 9; i < *size; i++) {
|
||||||
inp_cpy[i-9] = input[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;
|
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;
|
||||||
|
}
|
||||||
|
1
util.h
1
util.h
@ -26,5 +26,6 @@
|
|||||||
void get_time(char *thetime);
|
void get_time(char *thetime);
|
||||||
char * str_replace(const char *string, const char *substr,
|
char * str_replace(const char *string, const char *substr,
|
||||||
const char *replacement);
|
const char *replacement);
|
||||||
|
int str_contains(char str[], int size, char ch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user