mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-12 23:33:03 +01:00
move prompt help command to global_commands.c
This commit is contained in:
parent
c0d4070b96
commit
e091b36b14
@ -15,21 +15,22 @@ struct cmd_func {
|
||||
void (*func)(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
};
|
||||
|
||||
#define GLOBAL_NUM_COMMANDS 12
|
||||
#define GLOBAL_NUM_COMMANDS 13
|
||||
|
||||
static struct cmd_func global_commands[] = {
|
||||
{ "/accept", cmd_accept },
|
||||
{ "/add", cmd_add },
|
||||
{ "/clear", cmd_clear },
|
||||
{ "/connect", cmd_connect },
|
||||
{ "/exit", cmd_quit },
|
||||
{ "/groupchat", cmd_groupchat },
|
||||
{ "/myid", cmd_myid },
|
||||
{ "/nick", cmd_nick },
|
||||
{ "/note", cmd_note },
|
||||
{ "/q", cmd_quit },
|
||||
{ "/quit", cmd_quit },
|
||||
{ "/status", cmd_status },
|
||||
{ "/accept", cmd_accept },
|
||||
{ "/add", cmd_add },
|
||||
{ "/clear", cmd_clear },
|
||||
{ "/connect", cmd_connect },
|
||||
{ "/exit", cmd_quit },
|
||||
{ "/groupchat", cmd_groupchat },
|
||||
{ "/help", cmd_prompt_help },
|
||||
{ "/myid", cmd_myid },
|
||||
{ "/nick", cmd_nick },
|
||||
{ "/note", cmd_note },
|
||||
{ "/q", cmd_quit },
|
||||
{ "/quit", cmd_quit },
|
||||
{ "/status", cmd_status },
|
||||
};
|
||||
|
||||
#define CHAT_NUM_COMMANDS 5
|
||||
@ -105,7 +106,9 @@ void execute(WINDOW *w, ToxWindow *prompt, Tox *m, int num, char *cmd, int mode)
|
||||
return;
|
||||
|
||||
/* Try to match input command to command functions. If non-global command mode is specified,
|
||||
try specified mode's commands first, then upon failure try global commands. */
|
||||
try specified mode's commands first, then upon failure try global commands.
|
||||
|
||||
Note: Global commands must come last in case of duplicate command names */
|
||||
switch (mode) {
|
||||
case CHAT_COMMAND_MODE:
|
||||
if (do_command(w, prompt, m, num, num_args, CHAT_NUM_COMMANDS, chat_commands, args) == 0)
|
||||
|
@ -260,6 +260,33 @@ void cmd_note(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char
|
||||
prompt_update_statusmessage(prompt, msg, len);
|
||||
}
|
||||
|
||||
void cmd_prompt_help(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
wclear(window);
|
||||
wattron(window, COLOR_PAIR(CYAN) | A_BOLD);
|
||||
wprintw(window, "\n\nCommands:\n");
|
||||
wattroff(window, A_BOLD);
|
||||
|
||||
wprintw(window, " /add <id> <message> : Add friend with optional message\n");
|
||||
wprintw(window, " /accept <n> : Accept friend request\n");
|
||||
wprintw(window, " /connect <ip> <port> <key> : Manually connect to a DHT server\n");
|
||||
wprintw(window, " /status <type> <message> : Set your status with optional note\n");
|
||||
wprintw(window, " /note <message> : Set a personal note\n");
|
||||
wprintw(window, " /nick <nickname> : Set your nickname\n");
|
||||
wprintw(window, " /groupchat : Create a group chat\n");
|
||||
wprintw(window, " /myid : Print your ID\n");
|
||||
wprintw(window, " /quit or /exit : Exit Toxic\n");
|
||||
wprintw(window, " /help : Print this message again\n");
|
||||
wprintw(window, " /clear : Clear this window\n");
|
||||
|
||||
wattron(window, A_BOLD);
|
||||
wprintw(window, " * Argument messages must be enclosed in quotation marks.\n");
|
||||
wprintw(window, " * Use the TAB key to navigate through the tabs.\n");
|
||||
wattroff(window, A_BOLD);
|
||||
|
||||
wattroff(window, COLOR_PAIR(CYAN));
|
||||
}
|
||||
|
||||
void cmd_quit(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
exit_toxic(m);
|
||||
|
@ -10,5 +10,6 @@ void cmd_groupchat(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv
|
||||
void cmd_myid(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_nick(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_note(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_prompt_help(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_quit(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_status(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
|
@ -365,9 +365,6 @@ static void close_file_sender(Tox *m, int i)
|
||||
|
||||
static void do_file_senders(Tox *m)
|
||||
{
|
||||
if (num_file_senders == 0)
|
||||
return;
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_file_senders; ++i) {
|
||||
|
36
src/prompt.c
36
src/prompt.c
@ -72,33 +72,6 @@ static int add_friend_request(uint8_t *public_key)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void print_prompt_help(ToxWindow *self)
|
||||
{
|
||||
wclear(self->window);
|
||||
wattron(self->window, COLOR_PAIR(CYAN) | A_BOLD);
|
||||
wprintw(self->window, "\n\nCommands:\n");
|
||||
wattroff(self->window, A_BOLD);
|
||||
|
||||
wprintw(self->window, " /add <id> <message> : Add friend with optional message\n");
|
||||
wprintw(self->window, " /accept <n> : Accept friend request\n");
|
||||
wprintw(self->window, " /connect <ip> <port> <key> : Manually connect to a DHT server\n");
|
||||
wprintw(self->window, " /status <type> <message> : Set your status with optional note\n");
|
||||
wprintw(self->window, " /note <message> : Set a personal note\n");
|
||||
wprintw(self->window, " /nick <nickname> : Set your nickname\n");
|
||||
wprintw(self->window, " /groupchat : Create a group chat\n");
|
||||
wprintw(self->window, " /myid : Print your ID\n");
|
||||
wprintw(self->window, " /quit or /exit : Exit Toxic\n");
|
||||
wprintw(self->window, " /help : Print this message again\n");
|
||||
wprintw(self->window, " /clear : Clear this window\n");
|
||||
|
||||
wattron(self->window, A_BOLD);
|
||||
wprintw(self->window, " * Argument messages must be enclosed in quotation marks.\n");
|
||||
wprintw(self->window, " * Use the TAB key to navigate through the tabs.\n");
|
||||
wattroff(self->window, A_BOLD);
|
||||
|
||||
wattroff(self->window, COLOR_PAIR(CYAN));
|
||||
}
|
||||
|
||||
static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
int x, y, y2, x2;
|
||||
@ -129,12 +102,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
/* RETURN key: execute command */
|
||||
else if (key == '\n') {
|
||||
wprintw(self->window, "\n");
|
||||
|
||||
if (!strncmp(prompt_buf, "/help", strlen("/help")))
|
||||
print_prompt_help(self);
|
||||
else
|
||||
execute(self->window, self, m, self->num, prompt_buf, GLOBAL_COMMAND_MODE);
|
||||
|
||||
execute(self->window, self, m, self->num, prompt_buf, GLOBAL_COMMAND_MODE);
|
||||
prompt_buf_pos = 0;
|
||||
prompt_buf[0] = '\0';
|
||||
}
|
||||
@ -212,7 +180,7 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
static void prompt_onInit(ToxWindow *self, Tox *m)
|
||||
{
|
||||
scrollok(self->window, true);
|
||||
print_prompt_help(self);
|
||||
execute(self->window, self, m, self->num, "/help", GLOBAL_COMMAND_MODE);
|
||||
wclrtoeol(self->window);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user