summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2014-02-05 10:19:59 +0100
committerSebastien Helleu <flashcode@flashtux.org>2014-02-09 12:55:41 +0100
commitadf547a47c9e194900ea4db95c64f95c7cef265c (patch)
tree37b08bdd5a078030bbd1a47cfd70d899859c84cb
parent77e49a99e666826e2b1dfeb938218fc5478831db (diff)
downloadweechat-adf547a47c9e194900ea4db95c64f95c7cef265c.zip
trigger: add option "addinput" in command /trigger
-rw-r--r--src/plugins/trigger/trigger-command.c99
-rw-r--r--src/plugins/trigger/trigger-completion.c2
-rw-r--r--src/plugins/trigger/trigger.c2
-rw-r--r--src/plugins/trigger/trigger.h3
4 files changed, 77 insertions, 29 deletions
diff --git a/src/plugins/trigger/trigger-command.c b/src/plugins/trigger/trigger-command.c
index 293a1d8f5..8c4723ec8 100644
--- a/src/plugins/trigger/trigger-command.c
+++ b/src/plugins/trigger/trigger-command.c
@@ -135,12 +135,11 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc,
{
struct t_trigger *ptr_trigger;
const char *option;
- char *value, **sargv;
- int i, type, count, index_option, enable, sargc;
+ char *value, **sargv, **items, input[1024];
+ int i, type, count, index_option, enable, sargc, num_items, rc;
/* make C compiler happy */
(void) data;
- (void) buffer;
sargv = NULL;
@@ -194,6 +193,13 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc,
weechat_printf_tags (NULL, "no_trigger",
" command: \"%s\"", option);
}
+ rc = weechat_config_integer (ptr_trigger->options[TRIGGER_OPTION_RETURN_CODE]);
+ if (rc != TRIGGER_RC_OK)
+ {
+ weechat_printf_tags (NULL, "no_trigger",
+ " return code: %s",
+ trigger_return_code_string[rc]);
+ }
}
}
else
@@ -268,6 +274,38 @@ trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc,
goto end;
}
+ /* add trigger command in input (to help trigger creation) */
+ if (weechat_strcasecmp (argv[1], "addinput") == 0)
+ {
+ type = TRIGGER_HOOK_SIGNAL;
+ if (argc >= 3)
+ {
+ type = trigger_search_hook_type (argv[2]);
+ if (type < 0)
+ {
+ weechat_printf_tags (NULL, "no_trigger",
+ _("%sError: invalid hook type \"%s\""),
+ weechat_prefix ("error"), argv[2]);
+ goto end;
+ }
+ }
+ items = weechat_string_split (trigger_hook_default_rc[type], ",", 0, 0,
+ &num_items);
+ snprintf (input, sizeof (input),
+ "/trigger add name %s \"%s\" \"%s\" \"%s\" \"%s\"%s%s%s",
+ trigger_hook_type_string[type],
+ trigger_hook_default_arguments[type],
+ trigger_hook_default_conditions[type],
+ trigger_hook_default_regex[type],
+ trigger_hook_default_command[type],
+ (items && (num_items > 0)) ? " \"" : "",
+ (items && (num_items > 0)) ? items[0] : "",
+ (items && (num_items > 0)) ? "\"" : "");
+ weechat_buffer_set (buffer, "input", input);
+ weechat_buffer_set (buffer, "input_pos", "13");
+ goto end;
+ }
+
/* set option in a trigger */
if (weechat_strcasecmp (argv[1], "set") == 0)
{
@@ -454,35 +492,43 @@ trigger_command_init ()
N_("list"
" || add <name> <hook> [\"<arguments>\" [\"<conditions>\" "
"[\"<regex>\" [\"<command>\" [\"<return_code>\"]]]]]"
+ " || addinput [<hook>]"
" || set <name> <option> <value>"
" || rename <name> <new_name>"
" || enable|disable|toggle|restart <name>|-all [<name>...]"
" || del <name>|-all [<name>...]"
" || monitor"),
- N_(" add: add a trigger\n"
- " name: name of trigger\n"
- " hook: signal, hsignal, modifier, print, timer\n"
- "arguments: arguments for the hook, depending on hook (separated by "
- "semicolons):\n"
- " signal: name(s) of signal\n"
- " hsignal: name(s) of hsignal\n"
- " modifier: name(s) of modifier\n"
- " print: buffer, tags, message, strip_colors\n"
- " timer: interval, align_second, max_calls\n"
- " set: set an option in a trigger\n"
- " option: name of option: name, hook, arguments, conditions, regex, "
- "command, return_code\n"
- " (for help on option, you can do /help "
+ N_(" add: add a trigger\n"
+ " name: name of trigger\n"
+ " hook: signal, hsignal, modifier, print, timer\n"
+ " arguments: arguments for the hook, depending on hook (separated "
+ "by semicolons):\n"
+ " signal: name(s) of signal\n"
+ " hsignal: name(s) of hsignal\n"
+ " modifier: name(s) of modifier\n"
+ " print: buffer, tags, message, strip_colors\n"
+ " timer: interval, align_second, max_calls\n"
+ " conditions: evaluated conditions for the trigger\n"
+ " regex: one or more regular expressions to replace strings "
+ "in variables\n"
+ " command: command to execute (many commands can be separated by "
+ "\";\"\n"
+ "return_code: return code in callback (ok (default), ok_eat, error)\n"
+ " addinput: set input with default arguments to create a trigger\n"
+ " set: set an option in a trigger\n"
+ " option: name of option: name, hook, arguments, conditions, "
+ "regex, command, return_code\n"
+ " (for help on option, you can do /help "
"trigger.trigger.<name>.<option>)\n"
- " value: new value for the option\n"
- " rename: rename a trigger\n"
- " enable: enable trigger(s)\n"
- " disable: disable trigger(s)\n"
- " toggle: toggle trigger(s)\n"
- " restart: restart trigger(s) (for timer)\n"
- " del: delete a trigger\n"
- " -all: do action on all triggers\n"
- " monitor: open the trigger monitor buffer\n"
+ " value: new value for the option\n"
+ " rename: rename a trigger\n"
+ " enable: enable trigger(s)\n"
+ " disable: disable trigger(s)\n"
+ " toggle: toggle trigger(s)\n"
+ " restart: restart trigger(s) (for timer)\n"
+ " del: delete a trigger\n"
+ " -all: do action on all triggers\n"
+ " monitor: open the trigger monitor buffer\n"
"\n"
"When a trigger callback is called, following actions are performed, "
"in this order:\n"
@@ -512,6 +558,7 @@ trigger_command_init ()
" || add %(trigger_names) %(trigger_hooks) %(trigger_hook_arguments) "
"%(trigger_hook_condition) %(trigger_hook_regex) "
"%(trigger_hook_command) %(trigger_hook_rc)"
+ " || addinput %(trigger_hooks)"
" || set %(trigger_names) %(trigger_options)|name %(trigger_option_value)"
" || rename %(trigger_names) %(trigger_names)"
" || enable|disable|toggle|restart|del %(trigger_names)|-all %(trigger_names)|%*"
diff --git a/src/plugins/trigger/trigger-completion.c b/src/plugins/trigger/trigger-completion.c
index b5e5fba68..c8ed9671f 100644
--- a/src/plugins/trigger/trigger-completion.c
+++ b/src/plugins/trigger/trigger-completion.c
@@ -277,7 +277,7 @@ trigger_completion_hook_condition_cb (void *data, const char *completion_item,
(void) buffer;
trigger_completion_add_default_for_hook (completion,
- trigger_hook_default_condition,
+ trigger_hook_default_conditions,
NULL);
weechat_hook_completion_list_add (completion, "\"\"", 0,
WEECHAT_LIST_POS_END);
diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c
index b8e93d02a..df5ab291b 100644
--- a/src/plugins/trigger/trigger.c
+++ b/src/plugins/trigger/trigger.c
@@ -51,7 +51,7 @@ char *trigger_hook_type_string[TRIGGER_NUM_HOOK_TYPES] =
{ "signal", "hsignal", "modifier", "print", "command_run", "timer" };
char *trigger_hook_default_arguments[TRIGGER_NUM_HOOK_TYPES] =
{ "xxx", "xxx", "xxx", "", "/cmd", "60000;0;0" };
-char *trigger_hook_default_condition[TRIGGER_NUM_HOOK_TYPES] =
+char *trigger_hook_default_conditions[TRIGGER_NUM_HOOK_TYPES] =
{ "${...}", "${...}", "${...}", "${...}", "${...}", "${...}" };
char *trigger_hook_default_regex[TRIGGER_NUM_HOOK_TYPES] =
{ "/abc/def", "/abc/def", "/abc/def", "/abc/def", "/abc/def", "/abc/def" };
diff --git a/src/plugins/trigger/trigger.h b/src/plugins/trigger/trigger.h
index bb15da356..7c72a52b4 100644
--- a/src/plugins/trigger/trigger.h
+++ b/src/plugins/trigger/trigger.h
@@ -98,11 +98,12 @@ 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_conditions[];
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 char *trigger_return_code_string[];
extern int trigger_return_code[];
extern struct t_trigger *triggers;
extern struct t_trigger *last_trigger;