Skip to content

Commit

Permalink
core: fix conversion of WeeChat bar colors to ANSI colors
Browse files Browse the repository at this point in the history
  • Loading branch information
flashcode committed May 11, 2024
1 parent 32b01a6 commit 1a0b942
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ChangeLog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ New features::

Bug fixes::

* core: fix conversion of WeeChat "default" color to ANSI color
* core: fix conversion of WeeChat colors to ANSI colors: "default", "bar_fg", "bar_bg", "bar_delim"
* 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"
Expand Down
33 changes: 33 additions & 0 deletions src/gui/gui-color.c
Original file line number Diff line number Diff line change
Expand Up @@ -1544,8 +1544,41 @@ gui_color_encode_ansi (const char *string)
switch (ptr_string[0])
{
case GUI_COLOR_BAR_FG_CHAR:
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
GUI_COLOR_ANSI_DEFAULT_FG);
string_dyn_concat (out, str_concat, -1);
ptr_string++;
break;
case GUI_COLOR_BAR_BG_CHAR:
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
GUI_COLOR_ANSI_DEFAULT_BG);
string_dyn_concat (out, str_concat, -1);
ptr_string++;
break;
case GUI_COLOR_BAR_DELIM_CHAR:
color = CONFIG_COLOR(config_color_chat_delimiters);
if (color & GUI_COLOR_EXTENDED_FLAG)
{
snprintf (str_concat, sizeof (str_concat),
"\x1B[48;5;%dm",
color & GUI_COLOR_EXTENDED_MASK);
}
else
{
ansi_color = gui_color_weechat_to_ansi (
CONFIG_COLOR(config_color_chat_delimiters));
snprintf (str_concat, sizeof (str_concat),
"\x1B[%dm",
(ansi_color < 0) ?
GUI_COLOR_ANSI_DEFAULT_FG :
((ansi_color < 8) ?
ansi_color + 40 : ansi_color - 8 + 100));
}
string_dyn_concat (out, str_concat, -1);
ptr_string++;
break;
case GUI_COLOR_BAR_START_INPUT_CHAR:
case GUI_COLOR_BAR_START_INPUT_HIDDEN_CHAR:
case GUI_COLOR_BAR_MOVE_CURSOR_CHAR:
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/gui/test-gui-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,24 @@ TEST(GuiColor, EncodeAnsi)
gui_color_get_custom ("default"));
WEE_CHECK_ENCODE_ANSI("test_" "\x1B[39m" "default", string);

/* text color: bar foreground -> ANSI: 39 (default fg color) */
snprintf (string, sizeof (string),
"test_" "%s" "bar_fg",
gui_color_get_custom ("bar_fg"));
WEE_CHECK_ENCODE_ANSI("test_" "\x1B[39m" "bar_fg", string);

/* text color: bar background -> ANSI: 49 (default bg color) */
snprintf (string, sizeof (string),
"test_" "%s" "bar_bg",
gui_color_get_custom ("bar_bg"));
WEE_CHECK_ENCODE_ANSI("test_" "\x1B[49m" "bar_bg", string);

/* text color: bar delimiter -> color in option weechat.color.chat_delimiters */
snprintf (string, sizeof (string),
"test_" "%s" "bar_delim",
gui_color_get_custom ("bar_delim"));
WEE_CHECK_ENCODE_ANSI("test_" "\x1B[48;5;22m" "bar_delim", string);

/* text color */
snprintf (string, sizeof (string),
"test_" "%s" "blue",
Expand Down

0 comments on commit 1a0b942

Please sign in to comment.