1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 06:16:40 +02:00

core: fix conversion of WeeChat "default" color to ANSI color

This commit is contained in:
Sébastien Helleu
2024-05-11 11:54:16 +02:00
parent a456c3db86
commit 32b01a606c
4 changed files with 44 additions and 32 deletions
+1
View File
@@ -55,6 +55,7 @@ New features::
Bug fixes::
* core: fix conversion of WeeChat "default" color to ANSI color
* core: fix recursive search of group in nicklist
* core: use nick offline highlight color for prefix of action message when the nick is offline with a highlight
* core: add missing hdata name "buffer" in hdata "hotlist"
+28 -32
View File
@@ -1351,14 +1351,13 @@ gui_color_encode_ansi (const char *string)
if (error && !error[0])
{
ansi_color = gui_color_weechat_to_ansi (color);
if (ansi_color >= 0)
{
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
(ansi_color < 8) ?
ansi_color + 30 : ansi_color - 8 + 90);
string_dyn_concat (out, str_concat, -1);
}
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
(ansi_color < 0) ?
GUI_COLOR_ANSI_DEFAULT_FG :
((ansi_color < 8) ?
ansi_color + 30 : ansi_color - 8 + 90));
string_dyn_concat (out, str_concat, -1);
}
ptr_string += 2;
}
@@ -1397,14 +1396,13 @@ gui_color_encode_ansi (const char *string)
if (error && !error[0])
{
ansi_color = gui_color_weechat_to_ansi (color);
if (ansi_color >= 0)
{
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
(ansi_color < 8) ?
ansi_color + 40 : ansi_color - 8 + 100);
string_dyn_concat (out, str_concat, -1);
}
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
(ansi_color < 0) ?
GUI_COLOR_ANSI_DEFAULT_BG :
((ansi_color < 8) ?
ansi_color + 40 : ansi_color - 8 + 100));
string_dyn_concat (out, str_concat, -1);
}
ptr_string += 2;
}
@@ -1453,14 +1451,13 @@ gui_color_encode_ansi (const char *string)
if (error && !error[0])
{
ansi_color = gui_color_weechat_to_ansi (color);
if (ansi_color >= 0)
{
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
(ansi_color < 8) ?
ansi_color + 30 : ansi_color - 8 + 90);
string_dyn_concat (out, str_concat, -1);
}
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
(ansi_color < 0) ?
GUI_COLOR_ANSI_DEFAULT_FG :
((ansi_color < 8) ?
ansi_color + 30 : ansi_color - 8 + 90));
string_dyn_concat (out, str_concat, -1);
}
ptr_string += 2;
}
@@ -1506,14 +1503,13 @@ gui_color_encode_ansi (const char *string)
if (error && !error[0])
{
ansi_color = gui_color_weechat_to_ansi (color);
if (ansi_color >= 0)
{
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
(ansi_color < 8) ?
ansi_color + 40 : ansi_color - 8 + 100);
string_dyn_concat (out, str_concat, -1);
}
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
(ansi_color < 0) ?
GUI_COLOR_ANSI_DEFAULT_BG :
((ansi_color < 8) ?
ansi_color + 40 : ansi_color - 8 + 100));
string_dyn_concat (out, str_concat, -1);
}
ptr_string += 2;
}
+3
View File
@@ -159,6 +159,9 @@ enum t_gui_color_enum
"([<>])|" \
"(\\[[0-9;?]*[A-Za-z]))"
#define GUI_COLOR_ANSI_DEFAULT_FG 39
#define GUI_COLOR_ANSI_DEFAULT_BG 49
#define GUI_COLOR_BUFFER_NAME "color"
/* color structure */
+12
View File
@@ -791,6 +791,12 @@ TEST(GuiColor, EncodeAnsi)
gui_color_get_custom ("-underline"));
WEE_CHECK_ENCODE_ANSI("test_" "\x1B[4m" "underline" "\x1B[24m" "_end", string);
/* text color: WeeChat: "default" -> ANSI: 39 (default fg color) */
snprintf (string, sizeof (string),
"test_" "%s" "default",
gui_color_get_custom ("default"));
WEE_CHECK_ENCODE_ANSI("test_" "\x1B[39m" "default", string);
/* text color */
snprintf (string, sizeof (string),
"test_" "%s" "blue",
@@ -809,6 +815,12 @@ TEST(GuiColor, EncodeAnsi)
gui_color_get_custom ("214"));
WEE_CHECK_ENCODE_ANSI("test_" "\x1B[38;5;214m" "214", string);
/* background color: WeeChat: "default" -> ANSI: 49 (default bg color) */
snprintf (string, sizeof (string),
"test_" "%s" "bg_default",
gui_color_get_custom (",default"));
WEE_CHECK_ENCODE_ANSI("test_" "\x1B[49m" "bg_default", string);
/* background color */
snprintf (string, sizeof (string),
"test_" "%s" "bg_red",