1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Add /clear autocompletion and improve help

Regards https://github.com/profanity-im/profanity/issues/855

https://github.com/profanity-im/profanity/pull/874 brought us the
`/clear` command. The author of that patch couldn't follow up with the
review boothj5 did.

So the autocompletion and updated help was missing.
This commit adds it.
This commit is contained in:
Michael Vetter 2019-10-05 16:19:53 +02:00
parent d7c00360ea
commit 684a9b1a56
3 changed files with 60 additions and 6 deletions

View File

@ -106,6 +106,7 @@ static char* _tray_autocomplete(ProfWin *window, const char *const input, gboole
static char* _presence_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _presence_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _clear_autocomplete(ProfWin *window, const char *const input, gboolean previous);
static char* _script_autocomplete_func(const char *const prefix, gboolean previous); static char* _script_autocomplete_func(const char *const prefix, gboolean previous);
@ -217,6 +218,7 @@ static Autocomplete statusbar_self_ac;
static Autocomplete statusbar_chat_ac; static Autocomplete statusbar_chat_ac;
static Autocomplete statusbar_room_ac; static Autocomplete statusbar_room_ac;
static Autocomplete statusbar_show_ac; static Autocomplete statusbar_show_ac;
static Autocomplete clear_ac;
void void
cmd_ac_init(void) cmd_ac_init(void)
@ -807,6 +809,9 @@ cmd_ac_init(void)
autocomplete_add(blocked_ac, "add"); autocomplete_add(blocked_ac, "add");
autocomplete_add(blocked_ac, "remove"); autocomplete_add(blocked_ac, "remove");
clear_ac = autocomplete_new();
autocomplete_add(clear_ac, "persist_history");
tray_ac = autocomplete_new(); tray_ac = autocomplete_new();
autocomplete_add(tray_ac, "on"); autocomplete_add(tray_ac, "on");
autocomplete_add(tray_ac, "off"); autocomplete_add(tray_ac, "off");
@ -1151,6 +1156,7 @@ cmd_ac_reset(ProfWin *window)
autocomplete_reset(statusbar_chat_ac); autocomplete_reset(statusbar_chat_ac);
autocomplete_reset(statusbar_room_ac); autocomplete_reset(statusbar_room_ac);
autocomplete_reset(statusbar_show_ac); autocomplete_reset(statusbar_show_ac);
autocomplete_reset(clear_ac);
autocomplete_reset(script_ac); autocomplete_reset(script_ac);
if (script_show_ac) { if (script_show_ac) {
@ -1288,6 +1294,7 @@ cmd_ac_uninit(void)
autocomplete_free(statusbar_chat_ac); autocomplete_free(statusbar_chat_ac);
autocomplete_free(statusbar_room_ac); autocomplete_free(statusbar_room_ac);
autocomplete_free(statusbar_show_ac); autocomplete_free(statusbar_show_ac);
autocomplete_free(clear_ac);
} }
static void static void
@ -1540,6 +1547,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
g_hash_table_insert(ac_funcs, "/presence", _presence_autocomplete); g_hash_table_insert(ac_funcs, "/presence", _presence_autocomplete);
g_hash_table_insert(ac_funcs, "/rooms", _rooms_autocomplete); g_hash_table_insert(ac_funcs, "/rooms", _rooms_autocomplete);
g_hash_table_insert(ac_funcs, "/statusbar", _statusbar_autocomplete); g_hash_table_insert(ac_funcs, "/statusbar", _statusbar_autocomplete);
g_hash_table_insert(ac_funcs, "/clear", _clear_autocomplete);
int len = strlen(input); int len = strlen(input);
char parsed[len+1]; char parsed[len+1];
@ -3415,3 +3423,21 @@ _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previ
return NULL; return NULL;
} }
static char*
_clear_autocomplete(ProfWin *window, const char *const input, gboolean previous)
{
char *result = NULL;
result = autocomplete_param_with_ac(input, "/clear", clear_ac, TRUE, previous);
if (result) {
return result;
}
result = autocomplete_param_with_func(input, "/clear persist_history", prefs_autocomplete_boolean_choice, previous);
if (result) {
return result;
}
return NULL;
}

View File

@ -1107,17 +1107,23 @@ static struct cmd_t command_defs[] =
}, },
{ "/clear", { "/clear",
parse_args, 0, 0, NULL, parse_args, 0, 2, NULL,
CMD_NOSUBFUNCS CMD_NOSUBFUNCS
CMD_MAINFUNC(cmd_clear) CMD_MAINFUNC(cmd_clear)
CMD_TAGS( CMD_TAGS(
CMD_TAG_UI) CMD_TAG_UI)
CMD_SYN( CMD_SYN(
"/clear") "/clear",
"/clear persist_history <on|off>")
CMD_DESC( CMD_DESC(
"Clear the current window.") "Clear the current window. "
CMD_NOARGS "If you set persist_history you can still access the history by pressing PAGE UP.")
CMD_NOEXAMPLES CMD_ARGS(
{ "persist_history on|off", "Whether or not to clear the screen persistently"})
CMD_EXAMPLES(
"/clear",
"/clear persist_history",
"/clear persist_history on")
}, },
{ "/quit", { "/quit",

View File

@ -5047,7 +5047,29 @@ cmd_tiny(ProfWin *window, const char *const command, gchar **args)
gboolean gboolean
cmd_clear(ProfWin *window, const char *const command, gchar **args) cmd_clear(ProfWin *window, const char *const command, gchar **args)
{ {
win_clear(window); if (args[0] == NULL) {
win_clear(window);
return TRUE;
} else {
if ((g_strcmp0(args[0], "persist_history") == 0) ) {
if (args[1] != NULL) {
if ((g_strcmp0(args[1], "on") == 0) || (g_strcmp0(args[1], "off") == 0)) {
_cmd_set_boolean_preference(args[1], command, "Persistant history", PREF_CLEAR_PERSIST_HISTORY);
return TRUE;
}
} else {
if (prefs_get_boolean(PREF_CLEAR_PERSIST_HISTORY)) {
win_println(window, THEME_DEFAULT, '!', " Persistantly clear screen : ON");
} else {
win_println(window, THEME_DEFAULT, '!', " Persistantly clear screen : OFF");
}
return TRUE;
}
}
}
cons_bad_cmd_usage(command);
return TRUE; return TRUE;
} }