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

Refactored invalid command usage

This commit is contained in:
James Booth 2014-04-09 22:05:31 +01:00
parent 26216f6c17
commit b9aac28ccc
3 changed files with 22 additions and 13 deletions

View File

@ -1252,19 +1252,7 @@ cmd_execute(const char * const command, const char * const inp)
if (cmd != NULL) { if (cmd != NULL) {
gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result); gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
if (result == FALSE) { if (result == FALSE) {
if (cmd->setting_func != NULL) { ui_invalid_command_usage(cmd->help.usage, cmd->setting_func);
cons_show("");
(*cmd->setting_func)();
cons_show("Usage: %s", cmd->help.usage);
} else {
cons_show("");
cons_show("Usage: %s", cmd->help.usage);
if (ui_current_win_type() == WIN_CHAT) {
char usage[strlen(cmd->help.usage) + 8];
sprintf(usage, "Usage: %s", cmd->help.usage);
ui_current_print_line(usage);
}
}
return TRUE; return TRUE;
} else { } else {
gboolean result = cmd->func(args, cmd->help); gboolean result = cmd->func(args, cmd->help);

View File

@ -520,6 +520,24 @@ _ui_handle_error(const char * const err_msg)
g_string_free(msg, TRUE); g_string_free(msg, TRUE);
} }
static void
_ui_invalid_command_usage(const char * const usage, void (**setting_func)(void))
{
if (setting_func != NULL) {
cons_show("");
(*setting_func)();
cons_show("Usage: %s", usage);
} else {
cons_show("");
cons_show("Usage: %s", usage);
if (ui_current_win_type() == WIN_CHAT) {
char usage_cpy[strlen(usage) + 8];
sprintf(usage_cpy, "Usage: %s", usage);
ui_current_print_line(usage_cpy);
}
}
}
static void static void
_ui_disconnected(void) _ui_disconnected(void)
{ {
@ -1896,4 +1914,5 @@ ui_init_module(void)
ui_input_clear = _ui_input_clear; ui_input_clear = _ui_input_clear;
ui_input_nonblocking = _ui_input_nonblocking; ui_input_nonblocking = _ui_input_nonblocking;
ui_replace_input = _ui_replace_input; ui_replace_input = _ui_replace_input;
ui_invalid_command_usage = _ui_invalid_command_usage;
} }

View File

@ -159,6 +159,8 @@ void (*ui_input_clear)(void);
void (*ui_input_nonblocking)(void); void (*ui_input_nonblocking)(void);
void (*ui_replace_input)(char *input, const char * const new_input, int *size); void (*ui_replace_input)(char *input, const char * const new_input, int *size);
void (*ui_invalid_command_usage)(const char * const usage, void (**setting_func)(void));
// console window actions // console window actions
void (*cons_show)(const char * const msg, ...); void (*cons_show)(const char * const msg, ...);
void (*cons_about)(void); void (*cons_about)(void);