summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.adoc1
-rw-r--r--src/gui/gui-color.c60
-rw-r--r--src/gui/gui-color.h3
-rw-r--r--tests/unit/gui/test-gui-color.cpp12
4 files changed, 44 insertions, 32 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 081a36528..3b2578884 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -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"
diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c
index b2721c552..c895d5e7c 100644
--- a/src/gui/gui-color.c
+++ b/src/gui/gui-color.c
@@ -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;
}
diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h
index ca438bb45..e55a0a86d 100644
--- a/src/gui/gui-color.h
+++ b/src/gui/gui-color.h
@@ -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 */
diff --git a/tests/unit/gui/test-gui-color.cpp b/tests/unit/gui/test-gui-color.cpp
index 40e98393e..d2f618429 100644
--- a/tests/unit/gui/test-gui-color.cpp
+++ b/tests/unit/gui/test-gui-color.cpp
@@ -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",