mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:23:02 +01:00
split lists up so only commands that work in given window autocomplete
This commit is contained in:
parent
674aa682e7
commit
4065715b78
26
src/chat.c
26
src/chat.c
@ -21,7 +21,29 @@ extern int store_data(Tox *m, char *path);
|
|||||||
extern FileSender file_senders[MAX_FILES];
|
extern FileSender file_senders[MAX_FILES];
|
||||||
extern ToxicFriend friends[MAX_FRIENDS_NUM];
|
extern ToxicFriend friends[MAX_FRIENDS_NUM];
|
||||||
|
|
||||||
extern cmd_list[TOT_NUM_COMMANDS][MAX_CMDNAME_SIZE];
|
#define AC_NUM_CHAT_COMMANDS 18
|
||||||
|
|
||||||
|
/* Array of chat command names used for tab completion. */
|
||||||
|
static const uint8_t chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||||
|
{ "/accept" },
|
||||||
|
{ "/add" },
|
||||||
|
{ "/clear" },
|
||||||
|
{ "/close" },
|
||||||
|
{ "/connect" },
|
||||||
|
{ "/exit" },
|
||||||
|
{ "/groupchat" },
|
||||||
|
{ "/help" },
|
||||||
|
{ "/invite" },
|
||||||
|
{ "/join" },
|
||||||
|
{ "/myid" },
|
||||||
|
{ "/nick" },
|
||||||
|
{ "/note" },
|
||||||
|
{ "/q" },
|
||||||
|
{ "/quit" },
|
||||||
|
{ "/savefile" },
|
||||||
|
{ "/sendfile" },
|
||||||
|
{ "/status" },
|
||||||
|
};
|
||||||
|
|
||||||
static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint16_t len)
|
static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint16_t len)
|
||||||
{
|
{
|
||||||
@ -350,7 +372,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
|||||||
|
|
||||||
else if (key == '\t') { /* TAB key: command */
|
else if (key == '\t') { /* TAB key: command */
|
||||||
if (ctx->len > 1 && ctx->line[0] == '/') {
|
if (ctx->len > 1 && ctx->line[0] == '/') {
|
||||||
int diff = complete_line(ctx->line, &ctx->pos, &ctx->len, cmd_list, TOT_NUM_COMMANDS,
|
int diff = complete_line(ctx->line, &ctx->pos, &ctx->len, chat_cmd_list, AC_NUM_CHAT_COMMANDS,
|
||||||
MAX_CMDNAME_SIZE);
|
MAX_CMDNAME_SIZE);
|
||||||
|
|
||||||
if (diff != -1) {
|
if (diff != -1) {
|
||||||
|
@ -39,28 +39,6 @@ static struct cmd_func chat_commands[] = {
|
|||||||
{ "/sendfile", cmd_sendfile },
|
{ "/sendfile", cmd_sendfile },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Array of all command names; used for tab completion. */
|
|
||||||
const uint8_t cmd_list[TOT_NUM_COMMANDS][MAX_CMDNAME_SIZE] = {
|
|
||||||
{ "/accept" },
|
|
||||||
{ "/add" },
|
|
||||||
{ "/clear" },
|
|
||||||
{ "/connect" },
|
|
||||||
{ "/exit" },
|
|
||||||
{ "/groupchat" },
|
|
||||||
{ "/help" },
|
|
||||||
{ "/invite" },
|
|
||||||
{ "/join" },
|
|
||||||
{ "/myid" },
|
|
||||||
{ "/nick" },
|
|
||||||
{ "/note" },
|
|
||||||
{ "/q" },
|
|
||||||
{ "/quit" },
|
|
||||||
{ "/savefile" },
|
|
||||||
{ "/sendfile" },
|
|
||||||
{ "/status" },
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Parses input command and puts args into arg array.
|
/* Parses input command and puts args into arg array.
|
||||||
Returns number of arguments on success, -1 on failure. */
|
Returns number of arguments on success, -1 on failure. */
|
||||||
static int parse_command(WINDOW *w, char *cmd, char (*args)[MAX_STR_SIZE])
|
static int parse_command(WINDOW *w, char *cmd, char (*args)[MAX_STR_SIZE])
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#define MAX_NUM_ARGS 4 /* Includes command */
|
#define MAX_NUM_ARGS 4 /* Includes command */
|
||||||
#define GLOBAL_NUM_COMMANDS 13
|
#define GLOBAL_NUM_COMMANDS 13
|
||||||
#define CHAT_NUM_COMMANDS 5
|
#define CHAT_NUM_COMMANDS 5
|
||||||
#define TOT_NUM_COMMANDS 17 /* -1 for duplicate /help command */
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
GLOBAL_COMMAND_MODE,
|
GLOBAL_COMMAND_MODE,
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "execute.h"
|
#include "execute.h"
|
||||||
#include "misc_tools.h"
|
#include "misc_tools.h"
|
||||||
#include "groupchat.h"
|
#include "groupchat.h"
|
||||||
|
#include "prompt.h"
|
||||||
|
|
||||||
extern char *DATA_FILE;
|
extern char *DATA_FILE;
|
||||||
extern int store_data(Tox *m, char *path);
|
extern int store_data(Tox *m, char *path);
|
||||||
@ -21,7 +22,8 @@ extern int store_data(Tox *m, char *path);
|
|||||||
static GroupChat groupchats[MAX_WINDOWS_NUM];
|
static GroupChat groupchats[MAX_WINDOWS_NUM];
|
||||||
static int max_groupchat_index = 0;
|
static int max_groupchat_index = 0;
|
||||||
|
|
||||||
extern cmd_list[TOT_NUM_COMMANDS][MAX_CMDNAME_SIZE];
|
/* temporary until group chats have unique commands */
|
||||||
|
extern glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE];
|
||||||
|
|
||||||
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
|
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
|
||||||
{
|
{
|
||||||
@ -107,7 +109,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
|||||||
uint8_t selfnick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
uint8_t selfnick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||||
tox_get_self_name(m, selfnick, TOX_MAX_NAME_LENGTH);
|
tox_get_self_name(m, selfnick, TOX_MAX_NAME_LENGTH);
|
||||||
|
|
||||||
bool nick_match = strcasestr(msg, selfnick);;
|
bool nick_match = strcasestr(msg, selfnick);
|
||||||
|
|
||||||
if (nick_match) {
|
if (nick_match) {
|
||||||
alert_type = WINDOW_ALERT_0;
|
alert_type = WINDOW_ALERT_0;
|
||||||
@ -313,7 +315,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
|||||||
diff = complete_line(ctx->line, &ctx->pos, &ctx->len, groupchats[self->num].peer_names,
|
diff = complete_line(ctx->line, &ctx->pos, &ctx->len, groupchats[self->num].peer_names,
|
||||||
groupchats[self->num].num_peers, TOX_MAX_NAME_LENGTH);
|
groupchats[self->num].num_peers, TOX_MAX_NAME_LENGTH);
|
||||||
else
|
else
|
||||||
diff = complete_line(ctx->line, &ctx->pos, &ctx->len, cmd_list, TOT_NUM_COMMANDS,
|
diff = complete_line(ctx->line, &ctx->pos, &ctx->len, glob_cmd_list, AC_NUM_GLOB_COMMANDS,
|
||||||
MAX_CMDNAME_SIZE);
|
MAX_CMDNAME_SIZE);
|
||||||
|
|
||||||
if (diff != -1) {
|
if (diff != -1) {
|
||||||
|
22
src/prompt.c
22
src/prompt.c
@ -17,7 +17,25 @@
|
|||||||
uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE] = {0};
|
uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE] = {0};
|
||||||
uint8_t num_frnd_requests = 0;
|
uint8_t num_frnd_requests = 0;
|
||||||
extern ToxWindow *prompt;
|
extern ToxWindow *prompt;
|
||||||
extern cmd_list[TOT_NUM_COMMANDS][MAX_CMDNAME_SIZE];
|
|
||||||
|
/* Array of global command names used for tab completion. */
|
||||||
|
const uint8_t glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||||
|
{ "/accept" },
|
||||||
|
{ "/add" },
|
||||||
|
{ "/clear" },
|
||||||
|
{ "/close" }, /* rm /close when groupchats gets its own list */
|
||||||
|
{ "/connect" },
|
||||||
|
{ "/exit" },
|
||||||
|
{ "/groupchat" },
|
||||||
|
{ "/help" },
|
||||||
|
{ "/join" },
|
||||||
|
{ "/myid" },
|
||||||
|
{ "/nick" },
|
||||||
|
{ "/note" },
|
||||||
|
{ "/q" },
|
||||||
|
{ "/quit" },
|
||||||
|
{ "/status" },
|
||||||
|
};
|
||||||
|
|
||||||
/* prevents input string from eating system messages: call this prior to printing a prompt message
|
/* prevents input string from eating system messages: call this prior to printing a prompt message
|
||||||
TODO: This is only a partial fix */
|
TODO: This is only a partial fix */
|
||||||
@ -148,7 +166,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
|
|||||||
|
|
||||||
} else if (key == '\t') { /* TAB key: completes command */
|
} else if (key == '\t') { /* TAB key: completes command */
|
||||||
if (prt->len > 1 && prt->line[0] == '/')
|
if (prt->len > 1 && prt->line[0] == '/')
|
||||||
complete_line(prt->line, &prt->pos, &prt->len, cmd_list, TOT_NUM_COMMANDS,
|
complete_line(prt->line, &prt->pos, &prt->len, glob_cmd_list, AC_NUM_GLOB_COMMANDS,
|
||||||
MAX_CMDNAME_SIZE);
|
MAX_CMDNAME_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#define X_OFST 2 /* offset to account for prompt char */
|
#define X_OFST 2 /* offset to account for prompt char */
|
||||||
|
|
||||||
|
#define AC_NUM_GLOB_COMMANDS 15
|
||||||
|
|
||||||
ToxWindow new_prompt(void);
|
ToxWindow new_prompt(void);
|
||||||
void prep_prompt_win(void);
|
void prep_prompt_win(void);
|
||||||
void prompt_init_statusbar(ToxWindow *self, Tox *m);
|
void prompt_init_statusbar(ToxWindow *self, Tox *m);
|
||||||
|
Loading…
Reference in New Issue
Block a user