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:
parent
26216f6c17
commit
b9aac28ccc
@ -1252,19 +1252,7 @@ cmd_execute(const char * const command, const char * const inp)
|
||||
if (cmd != NULL) {
|
||||
gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
|
||||
if (result == FALSE) {
|
||||
if (cmd->setting_func != NULL) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
ui_invalid_command_usage(cmd->help.usage, cmd->setting_func);
|
||||
return TRUE;
|
||||
} else {
|
||||
gboolean result = cmd->func(args, cmd->help);
|
||||
|
@ -520,6 +520,24 @@ _ui_handle_error(const char * const err_msg)
|
||||
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
|
||||
_ui_disconnected(void)
|
||||
{
|
||||
@ -1896,4 +1914,5 @@ ui_init_module(void)
|
||||
ui_input_clear = _ui_input_clear;
|
||||
ui_input_nonblocking = _ui_input_nonblocking;
|
||||
ui_replace_input = _ui_replace_input;
|
||||
ui_invalid_command_usage = _ui_invalid_command_usage;
|
||||
}
|
||||
|
@ -159,6 +159,8 @@ void (*ui_input_clear)(void);
|
||||
void (*ui_input_nonblocking)(void);
|
||||
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
|
||||
void (*cons_show)(const char * const msg, ...);
|
||||
void (*cons_about)(void);
|
||||
|
Loading…
Reference in New Issue
Block a user