1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 08:43:13 +02:00

core: add option -color in command /pipe

This commit is contained in:
Sébastien Helleu
2025-02-01 09:37:22 +01:00
parent 04aea1bcb5
commit daef5971ae
17 changed files with 638 additions and 378 deletions
+28 -4
View File
@@ -4979,7 +4979,8 @@ COMMAND_CALLBACK(pipe)
const char *ptr_command, *ptr_filename, *ptr_hsignal;
const char *ptr_concat_separator, *ptr_strip_chars;
char *command, space[2] = " ", newline[2] = "\n";
int i, index_command, skip_empty_lines, send_to_buffer, no_locale, pipe_set;
int i, index_command, skip_empty_lines, send_to_buffer, no_locale;
int pipe_set, color, color_set;
struct t_gui_buffer *ptr_buffer;
/* make C compiler happy */
@@ -5002,6 +5003,8 @@ COMMAND_CALLBACK(pipe)
ptr_filename = NULL;
ptr_hsignal = NULL;
ptr_command = NULL;
color = GUI_CHAT_PIPE_COLOR_STRIP;
color_set = 0;
for (i = 1; i < argc; i++)
{
@@ -5070,6 +5073,22 @@ COMMAND_CALLBACK(pipe)
ptr_hsignal = argv[i];
index_command = i + 1;
}
else if (string_strcmp (argv[i], "-color") == 0)
{
COMMAND_MIN_ARGS(i + 2, argv[i]);
i++;
color = gui_chat_pipe_search_color (argv[i]);
if (color < 0)
{
gui_chat_printf (NULL,
_("%sInvalid color: \"%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
argv[i]);
return WEECHAT_RC_ERROR;
}
color_set = 1;
index_command = i + 1;
}
else
break;
}
@@ -5120,6 +5139,8 @@ COMMAND_CALLBACK(pipe)
gui_chat_pipe_buffer = (ptr_buffer) ? ptr_buffer : buffer;
if (!gui_chat_pipe_buffer)
COMMAND_ERROR;
if (!color_set && !send_to_buffer)
color = GUI_CHAT_PIPE_COLOR_KEEP;
if (gui_chat_pipe_buffer->type != GUI_BUFFER_TYPE_FORMATTED)
{
gui_chat_printf (NULL,
@@ -5145,6 +5166,7 @@ COMMAND_CALLBACK(pipe)
gui_chat_pipe_skip_empty_lines = skip_empty_lines;
if (no_locale)
setlocale (LC_ALL, "C");
gui_chat_pipe_color = color;
pipe_set = 1;
gui_chat_pipe = 1;
}
@@ -9337,8 +9359,8 @@ command_init ()
N_("redirect command output to a buffer, a file or a hsignal"),
/* TRANSLATORS: only text between angle brackets (eg: "<name>") may be translated */
N_("[-buffer <name>|-file <filename>|-hsignal <name>] "
"[-concat <separator>] [-strip <chars>] [-skipempty] [-c] [-o] "
"[-g] [-nl] <command>"),
"[-color strip|keep|ansi] [-concat <separator>] "
"[-strip <chars>] [-skipempty] [-c] [-o] [-g] [-nl] <command>"),
CMD_ARGS_DESC(
N_("raw[-buffer]: display command output on this buffer"),
N_("name: full buffer name (examples: \"core.weechat\", "
@@ -9347,6 +9369,7 @@ command_init ()
N_("raw[-hsignal]: send command output as hsignal; "
"keys: \"command\", \"output\" (lines separated by separator) "
"and \"tags\" (tags of each line separated by newline)"),
N_("raw[-color]: convert colors"),
N_("raw[-o]: send command output to the buffer as input; "
"colors are stripped and commands are NOT executed "
"(used only with -buffer)"),
@@ -9383,7 +9406,8 @@ command_init ()
"-buffer %(buffers_plugins_names) %(commands:/)|%*"
" || -file %(filename) %(commands:/)|%*"
" || -hsignal %- %(commands:/)|%*"
" || -o %(commands:/)|%*",
" || -o %(commands:/)|%*"
" || %(commands:/)|%*",
&command_pipe, NULL, NULL);
hook_command (
NULL, "plugin",