diff options
author | Michael Vetter <jubalh@iodoru.org> | 2022-03-21 10:35:07 +0100 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2022-03-21 10:35:07 +0100 |
commit | 09e7f63c790089acfe1fd39f686597891cada5a7 (patch) | |
tree | 93203a149313c420176fc710ce0cd0b910a00da4 | |
parent | 024694215dce1be21b09b8096eb499f107563f66 (diff) | |
download | profani-tty-09e7f63c790089acfe1fd39f686597891cada5a7.tar.gz |
Add adhoc cmd autocompletion
Add tab completion for `/cmd`. Complete the `list` and `exec` subcommands. Didn't complete the `<jid>` part since I think it's usually used for components and etc. Things that might not be in the roster. Fix https://github.com/profanity-im/profanity/issues/1650
-rw-r--r-- | src/command/cmd_ac.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index bb703cfb..8b380b55 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -130,6 +130,7 @@ static char* _executable_autocomplete(ProfWin* window, const char* const input, static char* _lastactivity_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _intype_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _mood_autocomplete(ProfWin* window, const char* const input, gboolean previous); +static char* _adhoc_cmd_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _script_autocomplete_func(const char* const prefix, gboolean previous, void* context); @@ -272,6 +273,7 @@ static Autocomplete executable_ac; static Autocomplete intype_ac; static Autocomplete mood_ac; static Autocomplete mood_type_ac; +static Autocomplete adhoc_cmd_ac; /*! * \brief Initialization of auto completion for commands. @@ -1146,6 +1148,10 @@ cmd_ac_init(void) autocomplete_add(mood_type_ac, "undefined"); autocomplete_add(mood_type_ac, "weak"); autocomplete_add(mood_type_ac, "worried"); + + adhoc_cmd_ac = autocomplete_new(); + autocomplete_add(adhoc_cmd_ac, "list"); + autocomplete_add(adhoc_cmd_ac, "exec"); } void @@ -1463,6 +1469,7 @@ cmd_ac_reset(ProfWin* window) autocomplete_reset(intype_ac); autocomplete_reset(mood_ac); autocomplete_reset(mood_type_ac); + autocomplete_reset(adhoc_cmd_ac); autocomplete_reset(script_ac); if (script_show_ac) { @@ -1627,6 +1634,7 @@ cmd_ac_uninit(void) autocomplete_free(url_ac); autocomplete_free(executable_ac); autocomplete_free(intype_ac); + autocomplete_free(adhoc_cmd_ac); } static void @@ -1893,6 +1901,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ g_hash_table_insert(ac_funcs, "/lastactivity", _lastactivity_autocomplete); g_hash_table_insert(ac_funcs, "/intype", _intype_autocomplete); g_hash_table_insert(ac_funcs, "/mood", _mood_autocomplete); + g_hash_table_insert(ac_funcs, "/cmd", _adhoc_cmd_autocomplete); int len = strlen(input); char parsed[len + 1]; @@ -4234,3 +4243,13 @@ _mood_autocomplete(ProfWin* window, const char* const input, gboolean previous) return result; } + +static char* +_adhoc_cmd_autocomplete(ProfWin* window, const char* const input, gboolean previous) +{ + char* result = NULL; + + result = autocomplete_param_with_ac(input, "/cmd", adhoc_cmd_ac, TRUE, previous); + + return result; +} |