1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 04:46:37 +02:00

trigger: add hook "info"

This commit is contained in:
Sébastien Helleu
2019-04-13 08:52:40 +02:00
parent 299c308f00
commit 8bc06ea101
25 changed files with 283 additions and 68 deletions
+30
View File
@@ -1170,6 +1170,36 @@ end:
TRIGGER_CALLBACK_CB_END(info);
}
/*
* Callback for an info hooked.
*/
char *
trigger_callback_info_cb (const void *pointer, void *data,
const char *info_name, const char *arguments)
{
const char *ptr_info;
char *info;
TRIGGER_CALLBACK_CB_INIT(NULL);
TRIGGER_CALLBACK_CB_NEW_EXTRA_VARS;
/* add data in hashtable used for conditions/replace/command */
weechat_hashtable_set (extra_vars, "tg_info_name", info_name);
weechat_hashtable_set (extra_vars, "tg_arguments", arguments);
weechat_hashtable_set (extra_vars, "tg_info", "");
/* execute the trigger (conditions, regex, command) */
trigger_callback_execute (trigger, NULL, pointers, extra_vars, NULL);
end:
ptr_info = weechat_hashtable_get (extra_vars, "tg_info");
info = (ptr_info) ? strdup (ptr_info) : NULL;
TRIGGER_CALLBACK_CB_END(info);
}
/*
* Initializes trigger callback.
*/
+4
View File
@@ -127,6 +127,10 @@ extern int trigger_callback_config_cb (const void *pointer, void *data,
extern struct t_hashtable *trigger_callback_focus_cb (const void *pointer,
void *data,
struct t_hashtable *info);
extern char *trigger_callback_info_cb (const void *pointer,
void *data,
const char *info_name,
const char *arguments);
extern void trigger_callback_init ();
extern void trigger_callback_end ();
+4 -2
View File
@@ -1157,7 +1157,7 @@ trigger_command_init ()
" addreplace: add or replace an existing trigger\n"
" name: name of trigger\n"
" hook: signal, hsignal, modifier, line, print, command, "
"command_run, timer, config, focus\n"
"command_run, timer, config, focus, info\n"
" arguments: arguments for the hook, depending on hook (separated "
"by semicolons):\n"
" signal: name(s) of signal (required)\n"
@@ -1172,6 +1172,7 @@ trigger_command_init ()
" timer: interval (required), align on second, max calls\n"
" config: name(s) of option (required)\n"
" focus: name(s) of area (required)\n"
" info: name(s) of info (required)\n"
" conditions: evaluated conditions for the trigger\n"
" regex: one or more regular expressions to replace strings "
"in variables\n"
@@ -1217,7 +1218,8 @@ trigger_command_init ()
" 2. replace text using POSIX extended regular expression(s) (if "
"defined in trigger)\n"
" 3. execute command(s) (if defined in trigger)\n"
" 4. exit with a return code (except for modifier, line and focus)\n"
" 4. exit with a return code (except for modifier, line, focus "
"and info)\n"
" 5. perform post action\n"
"\n"
"Examples (you can also look at default triggers with /trigger "
+24 -5
View File
@@ -50,20 +50,20 @@ char *trigger_option_default[TRIGGER_NUM_OPTIONS] =
char *trigger_hook_type_string[TRIGGER_NUM_HOOK_TYPES] =
{ "signal", "hsignal", "modifier", "line", "print", "command", "command_run",
"timer", "config", "focus" };
"timer", "config", "focus", "info" };
char *trigger_hook_option_values =
"signal|hsignal|modifier|line|print|command|command_run|timer|config|"
"focus";
"focus|info";
char *trigger_hook_default_arguments[TRIGGER_NUM_HOOK_TYPES] =
{ "xxx", "xxx", "xxx", "", "", "cmd;desc;args;args_desc;%(buffers_names)",
"/cmd", "60000;0;0", "xxx", "chat" };
"/cmd", "60000;0;0", "xxx", "chat", "xxx" };
char *trigger_hook_default_rc[TRIGGER_NUM_HOOK_TYPES] =
{ "ok,ok_eat,error", "ok,ok_eat,error", "", "", "ok,error", "ok,error",
"ok,ok_eat,error", "ok", "ok", "" };
"ok,ok_eat,error", "ok", "ok", "", "" };
char *trigger_hook_regex_default_var[TRIGGER_NUM_HOOK_TYPES] =
{ "tg_signal_data", "", "tg_string", "message", "tg_message", "tg_argv_eol1",
"tg_command", "tg_remaining_calls", "tg_value", "" };
"tg_command", "tg_remaining_calls", "tg_value", "", "tg_info" };
char *trigger_return_code_string[TRIGGER_NUM_RETURN_CODES] =
{ "ok", "ok_eat", "error" };
@@ -490,6 +490,25 @@ trigger_hook (struct t_trigger *trigger)
}
}
break;
case TRIGGER_HOOK_INFO:
if (argv && (argc >= 1))
{
trigger->hooks = malloc (argc * sizeof (trigger->hooks[0]));
if (trigger->hooks)
{
trigger->hooks_count = argc;
for (i = 0; i < argc; i++)
{
trigger->hooks[i] = weechat_hook_info (
argv[i],
NULL,
NULL,
&trigger_callback_info_cb,
trigger, NULL);
}
}
}
break;
}
if (!trigger->hooks)
+1
View File
@@ -55,6 +55,7 @@ enum t_trigger_hook_type
TRIGGER_HOOK_TIMER,
TRIGGER_HOOK_CONFIG,
TRIGGER_HOOK_FOCUS,
TRIGGER_HOOK_INFO,
/* number of hook types */
TRIGGER_NUM_HOOK_TYPES,
};