1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-10 03:33:12 +02:00

exec: add option "-color" in command /exec (decode ANSI colors by default)

The ANSI colors are decoded by default to WeeChat colors (for local display),
or IRC colors (if output is sent to buffer with "-o").
This commit is contained in:
Sebastien Helleu
2014-03-15 11:30:08 +01:00
parent d3c85c920c
commit 298f0211c1
4 changed files with 69 additions and 3 deletions
+40
View File
@@ -44,6 +44,33 @@ struct t_exec_cmd *exec_cmds = NULL; /* first executed command */
struct t_exec_cmd *last_exec_cmd = NULL; /* last executed command */
int exec_cmds_count = 0; /* number of executed commands */
char *exec_color_string[EXEC_NUM_COLORS] =
{ "off", "decode", "strip" };
/*
* Searches for a color action name.
*
* Returns index of color in enum t_exec_color, -1 if not found.
*/
int
exec_search_color (const char *color)
{
int i;
if (!color)
return -1;
for (i = 0; i < EXEC_NUM_COLORS; i++)
{
if (weechat_strcasecmp (exec_color_string[i], color) == 0)
return i;
}
/* color not found */
return -1;
}
/*
* Searches for an executed command by id, which can be a number or a name.
@@ -225,6 +252,19 @@ exec_command_display_output (struct t_exec_cmd *exec_cmd,
if (!line)
break;
if (exec_cmd->color != EXEC_COLOR_OFF)
{
line2 = weechat_hook_modifier_exec (
(exec_cmd->output_to_buffer) ?
"irc_color_decode_ansi" : "color_decode_ansi",
(exec_cmd->color == EXEC_COLOR_DECODE) ? "1" : "0",
line);
free (line);
if (!line2)
break;
line = line2;
}
if (exec_cmd->output_to_buffer)
{
if (exec_cmd->line_numbers)