mirror of
https://github.com/weechat/weechat.git
synced 2026-06-27 21:36:37 +02:00
relay/api: add a way to toggle between remote and local command execution on remote buffers (issue #2148)
New default key: - Alt+Ctrl+l (L): toggle execution of commands: remote/local New options: - relay.api.remote_input_cmd_local: text displayed for command executed locally - relay.api.remote_input_cmd_remote: text displayed for command executed on the remote WeeChat
This commit is contained in:
@@ -475,7 +475,7 @@ relay_command_remote (const void *pointer, void *data,
|
||||
char **argv, char **argv_eol)
|
||||
{
|
||||
struct t_relay_remote *ptr_remote, *ptr_remote2;
|
||||
int i, detailed_list, one_remote_found, update;
|
||||
int i, detailed_list, one_remote_found, update, input_get_any_user_data;
|
||||
const char *ptr_autoconnect, *ptr_autoreconnect_delay, *ptr_proxy;
|
||||
const char *ptr_tls_verify, *ptr_password;
|
||||
const char *ptr_totp_secret;
|
||||
@@ -846,6 +846,20 @@ relay_command_remote (const void *pointer, void *data,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
if (weechat_strcmp (argv[1], "togglecmd") == 0)
|
||||
{
|
||||
if (relay_remote_search (
|
||||
weechat_buffer_get_string (buffer, "localvar_relay_remote")))
|
||||
{
|
||||
input_get_any_user_data = weechat_buffer_get_integer (
|
||||
buffer, "input_get_any_user_data");
|
||||
weechat_buffer_set (buffer, "input_get_any_user_data",
|
||||
(input_get_any_user_data) ? "0" : "1");
|
||||
weechat_bar_item_update ("input_text");
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
WEECHAT_COMMAND_ERROR;
|
||||
}
|
||||
|
||||
@@ -941,7 +955,8 @@ relay_command_init ()
|
||||
" || add|addreplace <name> <url> [-<option>[=<value>]]"
|
||||
" || connect|reconnect|disconnect|del <name>"
|
||||
" || send <name> <json>"
|
||||
" || rename <name> <new_name>"),
|
||||
" || rename <name> <new_name>"
|
||||
" || togglecmd"),
|
||||
WEECHAT_CMD_ARGS_DESC(
|
||||
N_("raw[list]: list remote relay servers "
|
||||
"(without argument, this list is displayed)"),
|
||||
@@ -960,6 +975,8 @@ relay_command_init ()
|
||||
N_("raw[del]: delete a remote relay server"),
|
||||
N_("raw[send]: send JSON data to a remote relay server"),
|
||||
N_("raw[rename]: rename a remote relay server"),
|
||||
N_("raw[togglecmd]: toggle execution of commands on a remote buffer: "
|
||||
"on the remote WeeChat or locally (default key: alt+ctrl+l)"),
|
||||
"",
|
||||
N_("Examples:"),
|
||||
AI(" /remote add example https://localhost:9000 "
|
||||
@@ -974,6 +991,7 @@ relay_command_init ()
|
||||
"-totp_secret=${xxx}|%*"
|
||||
" || connect|reconnect|disconnect|del %(relay_remotes)"
|
||||
" || send %(relay_remotes) {\"request\":\"\"}"
|
||||
" || rename %(relay_remotes) %(relay_remotes)",
|
||||
" || rename %(relay_remotes) %(relay_remotes)"
|
||||
" || togglecmd",
|
||||
&relay_command_remote, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -105,9 +105,11 @@ struct t_config_option *relay_config_irc_backlog_time_format = NULL;
|
||||
|
||||
/* relay config, api section */
|
||||
|
||||
struct t_config_option *relay_config_api_remote_get_lines = NULL;
|
||||
struct t_config_option *relay_config_api_remote_autoreconnect_delay_growing = NULL;
|
||||
struct t_config_option *relay_config_api_remote_autoreconnect_delay_max = NULL;
|
||||
struct t_config_option *relay_config_api_remote_get_lines = NULL;
|
||||
struct t_config_option *relay_config_api_remote_input_cmd_local = NULL;
|
||||
struct t_config_option *relay_config_api_remote_input_cmd_remote = NULL;
|
||||
|
||||
/* other */
|
||||
|
||||
@@ -1851,13 +1853,6 @@ relay_config_init ()
|
||||
NULL, NULL, NULL);
|
||||
if (relay_config_section_api)
|
||||
{
|
||||
relay_config_api_remote_get_lines = weechat_config_new_option (
|
||||
relay_config_file, relay_config_section_api,
|
||||
"remote_get_lines", "integer",
|
||||
N_("number of lines to retrieve on each buffer when connecting "
|
||||
"to a remote relay"),
|
||||
NULL, 0, INT_MAX, "1000", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
relay_config_api_remote_autoreconnect_delay_growing = weechat_config_new_option (
|
||||
relay_config_file, relay_config_section_api,
|
||||
"remote_autoreconnect_delay_growing", "integer",
|
||||
@@ -1872,6 +1867,29 @@ relay_config_init ()
|
||||
"maximum)"),
|
||||
NULL, 0, 3600 * 24 * 7, "600", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
relay_config_api_remote_get_lines = weechat_config_new_option (
|
||||
relay_config_file, relay_config_section_api,
|
||||
"remote_get_lines", "integer",
|
||||
N_("number of lines to retrieve on each buffer when connecting "
|
||||
"to a remote relay"),
|
||||
NULL, 0, INT_MAX, "1000", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
relay_config_api_remote_input_cmd_local = weechat_config_new_option (
|
||||
relay_config_file, relay_config_section_api,
|
||||
"remote_input_cmd_local", "string",
|
||||
N_("text displayed after user input when the command would be "
|
||||
"executed locally (NOT sent to the remote WeeChat) "
|
||||
"(note: content is evaluated, see /help eval)"),
|
||||
NULL, 0, 0, " ${color:green}<local cmd>", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
relay_config_api_remote_input_cmd_remote = weechat_config_new_option (
|
||||
relay_config_file, relay_config_section_api,
|
||||
"remote_input_cmd_remote", "string",
|
||||
N_("text displayed after user input when the command would be "
|
||||
"executed on the remote WeeChat (NOT executed locally) "
|
||||
"(note: content is evaluated, see /help eval)"),
|
||||
NULL, 0, 0, " ${color:red}<remote cmd>", NULL, 0,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* section port */
|
||||
|
||||
@@ -70,9 +70,11 @@ extern struct t_config_option *relay_config_irc_backlog_since_last_message;
|
||||
extern struct t_config_option *relay_config_irc_backlog_tags;
|
||||
extern struct t_config_option *relay_config_irc_backlog_time_format;
|
||||
|
||||
extern struct t_config_option *relay_config_api_remote_get_lines;
|
||||
extern struct t_config_option *relay_config_api_remote_autoreconnect_delay_growing;
|
||||
extern struct t_config_option *relay_config_api_remote_autoreconnect_delay_max;
|
||||
extern struct t_config_option *relay_config_api_remote_get_lines;
|
||||
extern struct t_config_option *relay_config_api_remote_input_cmd_local;
|
||||
extern struct t_config_option *relay_config_api_remote_input_cmd_remote;
|
||||
|
||||
extern int relay_config_auto_open_buffer[];
|
||||
extern int relay_config_display_clients[];
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
@@ -251,6 +252,76 @@ relay_debug_dump_cb (const void *pointer, void *data,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates input text by adding local/remote command indicator, only on
|
||||
* buffers with remote (relay api).
|
||||
*/
|
||||
|
||||
char *
|
||||
relay_modifier_input_text_display_cb (const void *pointer,
|
||||
void *data,
|
||||
const char *modifier,
|
||||
const char *modifier_data,
|
||||
const char *string)
|
||||
{
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
struct t_relay_remote *ptr_remote;
|
||||
const char *ptr_input, *ptr_text_local, *ptr_text_remote;
|
||||
char *text, *new_input;
|
||||
int rc, input_get_any_user_data;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) modifier;
|
||||
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
if (!relay_remotes)
|
||||
return NULL;
|
||||
|
||||
rc = sscanf (modifier_data, "%p", &ptr_buffer);
|
||||
if ((rc == EOF) || (rc == 0))
|
||||
return NULL;
|
||||
|
||||
if (weechat_buffer_get_pointer (ptr_buffer, "plugin") != weechat_plugin)
|
||||
return NULL;
|
||||
|
||||
ptr_text_local = weechat_config_string (relay_config_api_remote_input_cmd_local);
|
||||
ptr_text_remote = weechat_config_string (relay_config_api_remote_input_cmd_remote);
|
||||
|
||||
if ((!ptr_text_local || !ptr_text_local[0])
|
||||
&& (!ptr_text_remote || !ptr_text_remote[0]))
|
||||
return NULL;
|
||||
|
||||
ptr_remote = relay_remote_search (
|
||||
weechat_buffer_get_string (ptr_buffer, "localvar_relay_remote"));
|
||||
if (!ptr_remote)
|
||||
return NULL;
|
||||
|
||||
ptr_input = weechat_string_input_for_buffer (
|
||||
weechat_buffer_get_string (ptr_buffer, "input"));
|
||||
|
||||
/* if input is not a command, we don't change the input */
|
||||
if (ptr_input)
|
||||
return NULL;
|
||||
|
||||
input_get_any_user_data = weechat_buffer_get_integer (
|
||||
ptr_buffer, "input_get_any_user_data");
|
||||
|
||||
text = weechat_string_eval_expression (
|
||||
(input_get_any_user_data) ? ptr_text_remote : ptr_text_local,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
weechat_asprintf (&new_input, "%s%s%s",
|
||||
string, weechat_color ("reset"), text);
|
||||
|
||||
free (text);
|
||||
|
||||
return new_input;
|
||||
}
|
||||
|
||||
/*
|
||||
* Timer callback, called each second.
|
||||
*/
|
||||
@@ -315,6 +386,14 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
|
||||
relay_info_init ();
|
||||
|
||||
/*
|
||||
* callback for adding local/remote command status (buffer api remote),
|
||||
* we use a low priority here, so that other modifiers "input_text_display"
|
||||
* (from other plugins) will be called before this one
|
||||
*/
|
||||
weechat_hook_modifier ("100|input_text_display",
|
||||
&relay_modifier_input_text_display_cb, NULL, NULL);
|
||||
|
||||
if (weechat_relay_plugin->upgrading)
|
||||
relay_upgrade_load ();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user