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

Command help now looked up

No longer need to write help strings in windows.c
Usage and help are part of the command structure
This commit is contained in:
James Booth 2012-08-14 22:06:27 +01:00
parent 4f4f780e60
commit 9fd7b2b3c2
3 changed files with 100 additions and 30 deletions

View File

@ -36,12 +36,6 @@
#include "prof_autocomplete.h" #include "prof_autocomplete.h"
#include "tinyurl.h" #include "tinyurl.h"
// command help strings
struct cmd_help_t {
const gchar *usage;
const gchar *short_help;
};
/* command structure /* command structure
* cmd - The actual string of the command * cmd - The actual string of the command
* func - The function to execute for the command * func - The function to execute for the command
@ -84,9 +78,9 @@ static gboolean _cmd_default(const char * const inp);
// The commands // The commands
static struct cmd_t main_commands[] = static struct cmd_t main_commands[] =
{ {
{ "/close", { "/help",
_cmd_close, _cmd_help,
{ NULL, "Close current chat window." } }, { "/help", "This help." } },
{ "/connect", { "/connect",
_cmd_connect, _cmd_connect,
@ -94,7 +88,7 @@ static struct cmd_t main_commands[] =
{ "/prefs", { "/prefs",
_cmd_prefs, _cmd_prefs,
{ NULL, "Show current preferences." } }, { "/prefs", "Show current preferences." } },
{ "/msg", { "/msg",
_cmd_msg, _cmd_msg,
@ -104,21 +98,21 @@ static struct cmd_t main_commands[] =
_cmd_tiny, _cmd_tiny,
{ "/tiny url", "Send url as tinyurl in current chat." } }, { "/tiny url", "Send url as tinyurl in current chat." } },
{ "/quit",
_cmd_quit,
{ NULL, "Quit Profanity." } },
{ "/ros", { "/ros",
_cmd_ros, _cmd_ros,
{ NULL, "List all contacts." } }, { "/ros", "List all contacts." } },
{ "/who", { "/who",
_cmd_who, _cmd_who,
{ NULL, "Find out who is online." } }, { "/who", "Find out who is online." } },
{ "/help", { "/close",
_cmd_help, _cmd_close,
{ NULL, "This help." } } { "/close", "Close current chat window." } },
{ "/quit",
_cmd_quit,
{ "/quit", "Quit Profanity." } }
}; };
static struct cmd_t setting_commands[] = static struct cmd_t setting_commands[] =
@ -232,6 +226,45 @@ reset_command_completer(void)
p_autocomplete_reset(commands_ac); p_autocomplete_reset(commands_ac);
} }
GSList *
cmd_get_help_list_basic(void)
{
GSList *result = NULL;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(main_commands); i++) {
result = g_slist_append(result, &((main_commands+i)->help));
}
return result;
}
GSList *
cmd_get_help_list_settings(void)
{
GSList *result = NULL;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(setting_commands); i++) {
result = g_slist_append(result, &((setting_commands+i)->help));
}
return result;
}
GSList *
cmd_get_help_list_status(void)
{
GSList *result = NULL;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(status_commands); i++) {
result = g_slist_append(result, &((status_commands+i)->help));
}
return result;
}
static gboolean static gboolean
_handle_command(const char * const command, const char * const inp) _handle_command(const char * const command, const char * const inp)
{ {

View File

@ -23,9 +23,18 @@
#ifndef COMMAND_H #ifndef COMMAND_H
#define COMMAND_H #define COMMAND_H
// command help strings
struct cmd_help_t {
const gchar *usage;
const gchar *short_help;
};
void command_init(void); void command_init(void);
gboolean process_input(char *inp); gboolean process_input(char *inp);
char * cmd_complete(char *inp); char * cmd_complete(char *inp);
void reset_command_completer(void); void reset_command_completer(void);
GSList * cmd_get_help_list_basic(void);
GSList * cmd_get_help_list_settings(void);
GSList * cmd_get_help_list_status(void);
#endif #endif

View File

@ -33,6 +33,7 @@
#include "ui.h" #include "ui.h"
#include "util.h" #include "util.h"
#include "contact.h" #include "contact.h"
#include "command.h"
#include "preferences.h" #include "preferences.h"
#include "tinyurl.h" #include "tinyurl.h"
@ -380,31 +381,58 @@ cons_help(void)
cons_show(""); cons_show("");
cons_show("Basic Commands:"); cons_show("Basic Commands:");
cons_show(""); cons_show("");
cons_show("/help : This help.");
cons_show("/prefs : Show current UI preferences."); GSList *basic_helpers = cmd_get_help_list_basic();
cons_show("/connect user@host : Login to jabber."); while (basic_helpers != NULL) {
cons_show("/msg user@host mesg : Send mesg to user."); struct cmd_help_t *help = (struct cmd_help_t *)basic_helpers->data;
cons_show("/tiny url : Send url as tinyurl in current chat."); char line[25 + 2 + strlen(help->short_help)];
cons_show("/close : Close a chat window."); sprintf(line, "%-25s: %s", help->usage, help->short_help);
cons_show("/who : Find out who is online."); cons_show(line);
cons_show("/ros : List all contacts."); basic_helpers = g_slist_next(basic_helpers);
cons_show("/quit : Quit Profanity."); }
cons_show(""); cons_show("");
cons_show("Settings:"); cons_show("Settings:");
cons_show(""); cons_show("");
GSList *settings_helpers = cmd_get_help_list_settings();
while (settings_helpers != NULL) {
struct cmd_help_t *help = (struct cmd_help_t *)settings_helpers->data;
char line[25 + 2 + strlen(help->short_help)];
sprintf(line, "%-25s: %s", help->usage, help->short_help);
cons_show(line);
settings_helpers = g_slist_next(settings_helpers);
}
/*
cons_show("/beep <on/off> : Enable/disable sound notification"); cons_show("/beep <on/off> : Enable/disable sound notification");
cons_show("/notify <on/off> : Enable/disable desktop notifications"); cons_show("/notify <on/off> : Enable/disable desktop notifications");
cons_show("/flash <on/off> : Enable/disable screen flash notification"); cons_show("/flash <on/off> : Enable/disable screen flash notification");
cons_show("/showsplash <on/off> : Enable/disable splash logo on startup"); cons_show("/showsplash <on/off> : Enable/disable splash logo on startup");
cons_show("/chlog <on/off> : Enable/disable chat logging"); cons_show("/chlog <on/off> : Enable/disable chat logging");
*/
cons_show(""); cons_show("");
cons_show("Status changes (msg is optional):"); cons_show("Status changes:");
cons_show(""); cons_show("");
GSList *status_helpers = cmd_get_help_list_status();
while (status_helpers != NULL) {
struct cmd_help_t *help = (struct cmd_help_t *)status_helpers->data;
char line[25 + 2 + strlen(help->short_help)];
sprintf(line, "%-25s: %s", help->usage, help->short_help);
cons_show(line);
status_helpers = g_slist_next(status_helpers);
}
/*
cons_show("/away <msg> : Set status to away."); cons_show("/away <msg> : Set status to away.");
cons_show("/online <msg> : Set status to online."); cons_show("/online <msg> : Set status to online.");
cons_show("/dnd <msg> : Set status to dnd (do not disturb)."); cons_show("/dnd <msg> : Set status to dnd (do not disturb).");
cons_show("/chat <msg> : Set status to chat (available for chat)."); cons_show("/chat <msg> : Set status to chat (available for chat).");
cons_show("/xa <msg> : Set status to xa (extended away)."); cons_show("/xa <msg> : Set status to xa (extended away).");
*/
cons_show(""); cons_show("");
cons_show("Navigation:"); cons_show("Navigation:");
cons_show(""); cons_show("");