From 70ed2a8189b8b1cec9b4c14a5f4cdc7137912b2c Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Thu, 14 Nov 2013 19:41:28 +0100 Subject: [PATCH] core: apply color attributes when clearing a window (patch #8236) (patch from Tom Alsberg) --- AUTHORS | 1 + ChangeLog | 1 + src/gui/curses/gui-curses-color.c | 32 +++++++++++++++++++++-------- src/gui/curses/gui-curses-window.c | 33 ++++++++++-------------------- src/gui/curses/gui-curses.h | 1 + 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/AUTHORS b/AUTHORS index fe14027b9..084a4a2fd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -68,6 +68,7 @@ Alphabetically: * Simon Kuhnle * Stefano Pigozzi * Stfn +* Tom Alsberg * Tor Hveem (xt) * Valentin Lorentz (progval) * Voroskoi diff --git a/ChangeLog b/ChangeLog index 0405f55e6..9d3e1e84c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] == Version 0.4.3 (under dev) +* core: apply color attributes when clearing a window (patch #8236) * core: set option weechat.look.paste_bracketed to "on" by default * core: fix truncated text when pasting several long lines (bug #40210) * core: rename option weechat.look.set_title to weechat.look.window_title, diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index 2b55d7bee..de8d65851 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -133,6 +133,29 @@ gui_color_search (const char *color_name) return -1; } +/* + * Get Curses attributes corresponding to extended attributes flags in a color. + */ + +int +gui_color_get_extended_attrs (int color) +{ + int attributes; + + attributes = 0; + + if (color & GUI_COLOR_EXTENDED_BOLD_FLAG) + attributes |= A_BOLD; + if (color & GUI_COLOR_EXTENDED_REVERSE_FLAG) + attributes |= A_REVERSE; + if (color & GUI_COLOR_EXTENDED_ITALIC_FLAG) + attributes |= A_ITALIC; + if (color & GUI_COLOR_EXTENDED_UNDERLINE_FLAG) + attributes |= A_UNDERLINE; + + return attributes; +} + /* * Assigns a WeeChat color (read from configuration). * @@ -511,14 +534,7 @@ gui_color_build (int number, int foreground, int background) gui_color[number]->foreground = gui_weechat_colors[foreground & GUI_COLOR_EXTENDED_MASK].foreground; gui_color[number]->attributes = gui_weechat_colors[foreground & GUI_COLOR_EXTENDED_MASK].attributes; } - if (foreground & GUI_COLOR_EXTENDED_BOLD_FLAG) - gui_color[number]->attributes |= A_BOLD; - if (foreground & GUI_COLOR_EXTENDED_REVERSE_FLAG) - gui_color[number]->attributes |= A_REVERSE; - if (foreground & GUI_COLOR_EXTENDED_ITALIC_FLAG) - gui_color[number]->attributes |= A_ITALIC; - if (foreground & GUI_COLOR_EXTENDED_UNDERLINE_FLAG) - gui_color[number]->attributes |= A_UNDERLINE; + gui_color[number]->attributes |= gui_color_get_extended_attrs (foreground); /* set background */ if (background & GUI_COLOR_EXTENDED_FLAG) diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 0406a905f..2d13cf712 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -176,7 +176,8 @@ gui_window_clear_weechat (WINDOW *window, int weechat_color) if (!gui_init_ok) return; - wbkgdset (window, ' ' | COLOR_PAIR (gui_color_weechat_get_pair (weechat_color))); + wbkgdset (window, ' ' | COLOR_PAIR (gui_color_weechat_get_pair (weechat_color)) | + gui_color[weechat_color]->attributes); werase (window); wmove (window, 0, 0); } @@ -188,9 +189,13 @@ gui_window_clear_weechat (WINDOW *window, int weechat_color) void gui_window_clear (WINDOW *window, int fg, int bg) { + int attrs; + if (!gui_init_ok) return; + attrs = gui_color_get_extended_attrs (fg); + if ((fg > 0) && (fg & GUI_COLOR_EXTENDED_FLAG)) fg &= GUI_COLOR_EXTENDED_MASK; else @@ -201,7 +206,7 @@ gui_window_clear (WINDOW *window, int fg, int bg) else bg = gui_weechat_colors[bg & GUI_COLOR_EXTENDED_MASK].background; - wbkgdset (window, ' ' | COLOR_PAIR (gui_color_get_pair (fg, bg))); + wbkgdset (window, ' ' | COLOR_PAIR (gui_color_get_pair (fg, bg)) | attrs); werase (window); wmove (window, 0, 0); } @@ -413,16 +418,8 @@ gui_window_set_custom_color_fg (WINDOW *window, int fg) { if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG)) gui_window_remove_color_style (window, A_ALL_ATTR); - attributes = 0; - if (fg & GUI_COLOR_EXTENDED_BOLD_FLAG) - attributes |= A_BOLD; - if (fg & GUI_COLOR_EXTENDED_REVERSE_FLAG) - attributes |= A_REVERSE; - if (fg & GUI_COLOR_EXTENDED_ITALIC_FLAG) - attributes |= A_ITALIC; - if (fg & GUI_COLOR_EXTENDED_UNDERLINE_FLAG) - attributes |= A_UNDERLINE; - attributes |= gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].attributes; + attributes = gui_color_get_extended_attrs (fg) | + gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].attributes; gui_window_set_color_style (window, attributes); fg = gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].foreground; @@ -505,16 +502,8 @@ gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg) { if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG)) gui_window_remove_color_style (window, A_ALL_ATTR); - attributes = 0; - if (fg & GUI_COLOR_EXTENDED_BOLD_FLAG) - attributes |= A_BOLD; - if (fg & GUI_COLOR_EXTENDED_REVERSE_FLAG) - attributes |= A_REVERSE; - if (fg & GUI_COLOR_EXTENDED_ITALIC_FLAG) - attributes |= A_ITALIC; - if (fg & GUI_COLOR_EXTENDED_UNDERLINE_FLAG) - attributes |= A_UNDERLINE; - attributes |= gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].attributes; + attributes = gui_color_get_extended_attrs (fg) | + gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].attributes; gui_window_set_color_style (window, attributes); fg = gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].foreground; diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h index 2ec767410..74345ae5d 100644 --- a/src/gui/curses/gui-curses.h +++ b/src/gui/curses/gui-curses.h @@ -85,6 +85,7 @@ extern int gui_color_buffer_refresh_needed; extern int gui_window_current_emphasis; /* color functions */ +extern int gui_color_get_extended_attrs (int color); extern int gui_color_get_pair (int fg, int bg); extern int gui_color_weechat_get_pair (int weechat_color); extern void gui_color_pre_init ();