diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2014-01-31 15:59:02 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2014-02-09 12:55:40 +0100 |
commit | 1496c8a25c22ffe998a29426e8ba8b3c82736ca6 (patch) | |
tree | b0e92c256f31f354613db838c67b9943ff048537 /src/plugins/trigger | |
parent | e372b8c8cb56c23411c5c3047f09cdb57aed06de (diff) | |
download | weechat-1496c8a25c22ffe998a29426e8ba8b3c82736ca6.zip |
trigger: add completion for all arguments of command /trigger add
Diffstat (limited to 'src/plugins/trigger')
-rw-r--r-- | src/plugins/trigger/trigger-command.c | 4 | ||||
-rw-r--r-- | src/plugins/trigger/trigger-completion.c | 204 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.c | 10 | ||||
-rw-r--r-- | src/plugins/trigger/trigger.h | 5 |
4 files changed, 222 insertions, 1 deletions
diff --git a/src/plugins/trigger/trigger-command.c b/src/plugins/trigger/trigger-command.c index 281b2de75..6435e973e 100644 --- a/src/plugins/trigger/trigger-command.c +++ b/src/plugins/trigger/trigger-command.c @@ -493,7 +493,9 @@ trigger_command_init () " silently save config each hour:\n" " /trigger add cfgsave timer 3600000;0;0 \"\" \"\" \"/mute /save\""), "list" - " || add %(trigger_names) %(trigger_hooks)" + " || add %(trigger_names) %(trigger_hooks) %(trigger_hook_arguments) " + "%(trigger_hook_condition) %(trigger_hook_regex) " + "%(trigger_hook_command) %(trigger_hook_rc)" " || set %(trigger_names) %(trigger_options)|name %(trigger_option_value)" " || rename %(trigger_names) %(trigger_names)" " || enable|disable|toggle|del %(trigger_names)|-all %(trigger_names)|%*" diff --git a/src/plugins/trigger/trigger-completion.c b/src/plugins/trigger/trigger-completion.c index 26dddb0fe..d9b0ce118 100644 --- a/src/plugins/trigger/trigger-completion.c +++ b/src/plugins/trigger/trigger-completion.c @@ -164,6 +164,195 @@ trigger_completion_hooks_cb (void *data, const char *completion_item, } /* + * Adds a word with quotes around to completion list. + */ + +void +trigger_completion_add_quoted_word (struct t_gui_completion *completion, + const char *word) +{ + char *temp; + int length; + + length = 1 + strlen (word) + 1 + 1; + temp = malloc (length); + if (!temp) + return; + + snprintf (temp, length, "\"%s\"", word); + weechat_hook_completion_list_add (completion, temp, 0, + WEECHAT_LIST_POS_END); + + free (temp); +} + +/* + * Adds a default string to completion list, depending on hook type. + * + * If split is not NULL, the default string found is split using this separator, + * and therefore many words can be added to completion list. + */ + +void +trigger_completion_add_default_for_hook (struct t_gui_completion *completion, + char *default_strings[], char *split) +{ + const char *args; + char **argv, **items; + int argc, num_items, type, i; + + args = weechat_hook_completion_get_string (completion, "args"); + if (!args) + return; + + argv = weechat_string_split (args, " ", 0, 0, &argc); + if (!argv) + return; + + if (argc >= 3) + { + type = trigger_search_hook_type (argv[2]); + if (type >= 0) + { + if (default_strings[type][0] && split && split[0]) + { + items = weechat_string_split (default_strings[type], split, + 0, 0, &num_items); + if (items) + { + for (i = 0; i < num_items; i++) + { + trigger_completion_add_quoted_word (completion, + items[i]); + } + weechat_string_free_split (items); + } + } + else + { + trigger_completion_add_quoted_word (completion, + default_strings[type]); + } + } + } + + weechat_string_free_split (argv); +} + +/* + * Adds default arguments for hook to completion list. + */ + +int +trigger_completion_hook_arguments_cb (void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + /* make C compiler happy */ + (void) data; + (void) completion_item; + (void) buffer; + + trigger_completion_add_default_for_hook (completion, + trigger_hook_default_arguments, + NULL); + weechat_hook_completion_list_add (completion, "\"\"", 0, + WEECHAT_LIST_POS_END); + + return WEECHAT_RC_OK; +} + +/* + * Adds default condition for hook to completion list. + */ + +int +trigger_completion_hook_condition_cb (void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + /* make C compiler happy */ + (void) data; + (void) completion_item; + (void) buffer; + + trigger_completion_add_default_for_hook (completion, + trigger_hook_default_condition, + NULL); + weechat_hook_completion_list_add (completion, "\"\"", 0, + WEECHAT_LIST_POS_END); + + return WEECHAT_RC_OK; +} + +/* + * Adds default regular expression for hook to completion list. + */ + +int +trigger_completion_hook_regex_cb (void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + /* make C compiler happy */ + (void) data; + (void) completion_item; + (void) buffer; + + trigger_completion_add_default_for_hook (completion, + trigger_hook_default_regex, + NULL); + weechat_hook_completion_list_add (completion, "\"\"", 0, + WEECHAT_LIST_POS_END); + + return WEECHAT_RC_OK; +} + +/* + * Adds default command for hook to completion list. + */ + +int +trigger_completion_hook_command_cb (void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + /* make C compiler happy */ + (void) data; + (void) completion_item; + (void) buffer; + + trigger_completion_add_default_for_hook (completion, + trigger_hook_default_command, + NULL); + weechat_hook_completion_list_add (completion, "\"\"", 0, + WEECHAT_LIST_POS_END); + + return WEECHAT_RC_OK; +} + +/* + * Adds default return code(s) for hook to completion list. + */ + +int +trigger_completion_hook_rc_cb (void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + /* make C compiler happy */ + (void) data; + (void) completion_item; + (void) buffer; + + trigger_completion_add_default_for_hook (completion, + trigger_hook_default_rc, + ","); + + return WEECHAT_RC_OK; +} + +/* * Hooks completions. */ @@ -182,4 +371,19 @@ trigger_completion_init () weechat_hook_completion ("trigger_hooks", N_("hooks for triggers"), &trigger_completion_hooks_cb, NULL); + weechat_hook_completion ("trigger_hook_arguments", + N_("default arguments for a hook"), + &trigger_completion_hook_arguments_cb, NULL); + weechat_hook_completion ("trigger_hook_condition", + N_("default condition for a hook"), + &trigger_completion_hook_condition_cb, NULL); + weechat_hook_completion ("trigger_hook_regex", + N_("default regular expression for a hook"), + &trigger_completion_hook_regex_cb, NULL); + weechat_hook_completion ("trigger_hook_command", + N_("default command for a hook"), + &trigger_completion_hook_command_cb, NULL); + weechat_hook_completion ("trigger_hook_rc", + N_("default return codes for hook callback"), + &trigger_completion_hook_rc_cb, NULL); } diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c index eaf71f126..e0f6e93a8 100644 --- a/src/plugins/trigger/trigger.c +++ b/src/plugins/trigger/trigger.c @@ -49,6 +49,16 @@ char *trigger_option_default[TRIGGER_NUM_OPTIONS] = char *trigger_hook_type_string[TRIGGER_NUM_HOOK_TYPES] = { "signal", "hsignal", "modifier", "print", "timer" }; +char *trigger_hook_default_arguments[TRIGGER_NUM_HOOK_TYPES] = +{ "xxx", "xxx", "xxx", "", "60000;0;0" }; +char *trigger_hook_default_condition[TRIGGER_NUM_HOOK_TYPES] = +{ "${...}", "${...}", "${...}", "${...}", "${...}" }; +char *trigger_hook_default_regex[TRIGGER_NUM_HOOK_TYPES] = +{ "/abc/def", "/abc/def", "/abc/def", "/abc/def", "" }; +char *trigger_hook_default_command[TRIGGER_NUM_HOOK_TYPES] = +{ "/cmd", "/cmd", "/cmd", "/cmd", "/cmd" }; +char *trigger_hook_default_rc[TRIGGER_NUM_HOOK_TYPES] = +{ "ok,ok_eat,error", "ok,ok_eat,error", "", "ok,error", "ok" }; char *trigger_hook_regex_default_var[TRIGGER_NUM_HOOK_TYPES] = { "tg_signal_data", "", "tg_string", "tg_message", "" }; diff --git a/src/plugins/trigger/trigger.h b/src/plugins/trigger/trigger.h index f665539e2..4fa43a6c9 100644 --- a/src/plugins/trigger/trigger.h +++ b/src/plugins/trigger/trigger.h @@ -96,6 +96,11 @@ extern struct t_weechat_plugin *weechat_trigger_plugin; extern char *trigger_option_string[]; extern char *trigger_option_default[]; extern char *trigger_hook_type_string[]; +extern char *trigger_hook_default_arguments[]; +extern char *trigger_hook_default_condition[]; +extern char *trigger_hook_default_regex[]; +extern char *trigger_hook_default_command[]; +extern char *trigger_hook_default_rc[]; extern char *trigger_hook_regex_default_var[]; extern int trigger_return_code[]; extern struct t_trigger *triggers; |