summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2011-10-15 13:54:53 +0200
committerSebastien Helleu <flashcode@flashtux.org>2011-10-15 13:54:53 +0200
commitac7c27949b8fb52fa2c7cb06fdf0d176607419b0 (patch)
tree656f2a19f607e048ddeba9b65d4b444657048abf /src/gui
parent0bbddad6a67c3349e5b3331aa863d031ba8f7bd3 (diff)
downloadweechat-ac7c27949b8fb52fa2c7cb06fdf0d176607419b0.zip
core: add color attribute "|" and value "resetcolor" for function weechat_color in plugin API (bug #34550)
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-bar-window.c6
-rw-r--r--src/gui/curses/gui-curses-chat.c69
-rw-r--r--src/gui/curses/gui-curses-window.c37
-rw-r--r--src/gui/curses/gui-curses.h1
-rw-r--r--src/gui/gui-color.c15
-rw-r--r--src/gui/gui-color.h2
6 files changed, 96 insertions, 34 deletions
diff --git a/src/gui/curses/gui-curses-bar-window.c b/src/gui/curses/gui-curses-bar-window.c
index e8d88406d..31501e458 100644
--- a/src/gui/curses/gui-curses-bar-window.c
+++ b/src/gui/curses/gui-curses-bar-window.c
@@ -283,6 +283,12 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
break;
}
break;
+ case GUI_COLOR_RESET_CHAR: /* reset color (keep attributes) */
+ string++;
+ gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
+ CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]),
+ CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG]));
+ break;
default:
gui_window_string_apply_color_weechat ((unsigned char **)&string,
GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar);
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 736f3e137..008e92cb5 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -107,25 +107,28 @@ gui_chat_marker_for_line (struct t_gui_buffer *buffer, struct t_gui_line *line)
void
gui_chat_reset_style (struct t_gui_window *window, struct t_gui_line *line,
+ int reset_attributes,
int color_inactive_window, int color_inactive_buffer,
int color_default)
{
+ int color;
+
+ color = color_default;
if ((window != gui_current_window) &&
CONFIG_BOOLEAN(config_look_color_inactive_window))
{
- gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat,
- color_inactive_window);
- return;
+ color = color_inactive_window;
}
- if (line && !(line->data->buffer->active)
- && CONFIG_BOOLEAN(config_look_color_inactive_buffer))
+ else if (line && !(line->data->buffer->active)
+ && CONFIG_BOOLEAN(config_look_color_inactive_buffer))
{
- gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat,
- color_inactive_buffer);
- return;
+ color = color_inactive_buffer;
}
- gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat,
- color_default);
+
+ if (reset_attributes)
+ gui_window_reset_style (GUI_WINDOW_OBJECTS(window)->win_chat, color);
+ else
+ gui_window_reset_color (GUI_WINDOW_OBJECTS(window)->win_chat, color);
}
/*
@@ -260,6 +263,24 @@ gui_chat_string_next_char (struct t_gui_window *window, struct t_gui_line *line,
break;
}
break;
+ case GUI_COLOR_RESET_CHAR: /* reset color (keep attributes) */
+ string++;
+ if (apply_style)
+ {
+ if (apply_style_inactive)
+ {
+ gui_chat_reset_style (window, line, 0,
+ GUI_COLOR_CHAT_INACTIVE_WINDOW,
+ GUI_COLOR_CHAT_INACTIVE_BUFFER,
+ GUI_COLOR_CHAT);
+ }
+ else
+ {
+ gui_window_reset_color (GUI_WINDOW_OBJECTS(window)->win_chat,
+ GUI_COLOR_CHAT);
+ }
+ }
+ break;
default:
gui_window_string_apply_color_weechat ((unsigned char **)&string,
(apply_style) ? GUI_WINDOW_OBJECTS(window)->win_chat : NULL);
@@ -282,7 +303,7 @@ gui_chat_string_next_char (struct t_gui_window *window, struct t_gui_line *line,
{
if (apply_style_inactive)
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
@@ -547,7 +568,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
{
if (window->win_chat_cursor_y < window->coords_size)
window->coords[window->win_chat_cursor_y].line = line;
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
@@ -568,7 +589,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
if (!simulate)
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
@@ -601,7 +622,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
{
if (!simulate)
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
@@ -617,7 +638,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
if (!simulate)
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
(CONFIG_BOOLEAN(config_look_color_inactive_buffer)
&& CONFIG_BOOLEAN(config_look_color_inactive_prefix_buffer)
@@ -673,7 +694,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
{
if (!simulate)
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
@@ -707,7 +728,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
{
if (!simulate)
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
@@ -753,7 +774,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
}
if (!simulate)
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
(CONFIG_BOOLEAN(config_look_color_inactive_buffer)
&& CONFIG_BOOLEAN(config_look_color_inactive_prefix)
@@ -767,7 +788,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
{
if (!simulate)
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
(CONFIG_BOOLEAN(config_look_color_inactive_buffer)
&& CONFIG_BOOLEAN(config_look_color_inactive_prefix)
@@ -813,7 +834,7 @@ gui_chat_display_time_to_prefix (struct t_gui_window *window,
if (!simulate)
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
@@ -944,14 +965,14 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
{
if (CONFIG_BOOLEAN(config_look_color_inactive_message))
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
}
else
{
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT,
GUI_COLOR_CHAT,
GUI_COLOR_CHAT);
@@ -1107,7 +1128,7 @@ gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
int y)
{
/* reset color & style for a new line */
- gui_chat_reset_style (window, line,
+ gui_chat_reset_style (window, line, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
@@ -1250,7 +1271,7 @@ gui_chat_draw (struct t_gui_buffer *buffer, int erase)
{
gui_window_coords_alloc (ptr_win);
- gui_chat_reset_style (ptr_win, NULL,
+ gui_chat_reset_style (ptr_win, NULL, 1,
GUI_COLOR_CHAT_INACTIVE_WINDOW,
GUI_COLOR_CHAT_INACTIVE_BUFFER,
GUI_COLOR_CHAT);
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index eae461294..238588da9 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -248,6 +248,17 @@ gui_window_reset_style (WINDOW *window, int weechat_color)
}
/*
+ * gui_window_reset_color: reset color with a weechat color for a window
+ */
+
+void
+gui_window_reset_color (WINDOW *window, int weechat_color)
+{
+ wattron (window, COLOR_PAIR(gui_color_weechat_get_pair (weechat_color)) |
+ gui_color[weechat_color]->attributes);
+}
+
+/*
* gui_window_set_color_style: set style for color
*/
@@ -333,15 +344,15 @@ gui_window_set_custom_color_fg (WINDOW *window, int fg)
{
if (fg & GUI_COLOR_EXTENDED_BOLD_FLAG)
gui_window_set_color_style (window, A_BOLD);
- else
+ else if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
gui_window_remove_color_style (window, A_BOLD);
if (fg & GUI_COLOR_EXTENDED_REVERSE_FLAG)
gui_window_set_color_style (window, A_REVERSE);
- else
+ else if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
gui_window_remove_color_style (window, A_REVERSE);
if (fg & GUI_COLOR_EXTENDED_UNDERLINE_FLAG)
gui_window_set_color_style (window, A_UNDERLINE);
- else
+ else if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
gui_window_remove_color_style (window, A_UNDERLINE);
gui_window_set_color (window,
fg & GUI_COLOR_EXTENDED_MASK,
@@ -349,8 +360,11 @@ gui_window_set_custom_color_fg (WINDOW *window, int fg)
}
else if ((fg & GUI_COLOR_EXTENDED_MASK) < GUI_CURSES_NUM_WEECHAT_COLORS)
{
- gui_window_remove_color_style (window,
- A_BOLD | A_REVERSE | A_UNDERLINE);
+ if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
+ {
+ gui_window_remove_color_style (window,
+ A_BOLD | A_REVERSE | A_UNDERLINE);
+ }
attributes = 0;
if (fg & GUI_COLOR_EXTENDED_BOLD_FLAG)
attributes |= A_BOLD;
@@ -425,22 +439,25 @@ gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg)
{
if (fg & GUI_COLOR_EXTENDED_BOLD_FLAG)
gui_window_set_color_style (window, A_BOLD);
- else
+ else if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
gui_window_remove_color_style (window, A_BOLD);
if (fg & GUI_COLOR_EXTENDED_REVERSE_FLAG)
gui_window_set_color_style (window, A_REVERSE);
- else
+ else if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
gui_window_remove_color_style (window, A_REVERSE);
if (fg & GUI_COLOR_EXTENDED_UNDERLINE_FLAG)
gui_window_set_color_style (window, A_UNDERLINE);
- else
+ else if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
gui_window_remove_color_style (window, A_UNDERLINE);
fg &= GUI_COLOR_EXTENDED_MASK;
}
else if ((fg & GUI_COLOR_EXTENDED_MASK) < GUI_CURSES_NUM_WEECHAT_COLORS)
{
- gui_window_remove_color_style (window,
- A_BOLD | A_REVERSE | A_UNDERLINE);
+ if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
+ {
+ gui_window_remove_color_style (window,
+ A_BOLD | A_REVERSE | A_UNDERLINE);
+ }
attributes = 0;
if (fg & GUI_COLOR_EXTENDED_BOLD_FLAG)
attributes |= A_BOLD;
diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h
index ddc48cede..1b223c401 100644
--- a/src/gui/curses/gui-curses.h
+++ b/src/gui/curses/gui-curses.h
@@ -88,6 +88,7 @@ extern void gui_window_redraw_buffer (struct t_gui_buffer *buffer);
extern void gui_window_clear (WINDOW *window, int fg, int bg);
extern void gui_window_clrtoeol (WINDOW *window);
extern void gui_window_reset_style (WINDOW *window, int num_color);
+extern void gui_window_reset_color (WINDOW *window, int num_color);
extern void gui_window_set_color_style (WINDOW *window, int style);
extern void gui_window_remove_color_style (WINDOW *window, int style);
extern void gui_window_set_color (WINDOW *window, int fg, int bg);
diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c
index 1dcb4c8b8..d2a8e94de 100644
--- a/src/gui/gui-color.c
+++ b/src/gui/gui-color.c
@@ -104,6 +104,9 @@ gui_color_attr_get_flag (char c)
if (c == GUI_COLOR_EXTENDED_UNDERLINE_CHAR)
return GUI_COLOR_EXTENDED_UNDERLINE_FLAG;
+ if (c == GUI_COLOR_EXTENDED_KEEPATTR_CHAR)
+ return GUI_COLOR_EXTENDED_KEEPATTR_FLAG;
+
return 0;
}
@@ -128,6 +131,8 @@ gui_color_attr_build_string (int color, char *str_attr)
str_attr[i++] = GUI_COLOR_EXTENDED_ITALIC_CHAR;
if (color & GUI_COLOR_EXTENDED_UNDERLINE_FLAG)
str_attr[i++] = GUI_COLOR_EXTENDED_UNDERLINE_CHAR;
+ if (color & GUI_COLOR_EXTENDED_KEEPATTR_FLAG)
+ str_attr[i++] = GUI_COLOR_EXTENDED_KEEPATTR_CHAR;
str_attr[i] = '\0';
}
@@ -159,6 +164,13 @@ gui_color_get_custom (const char *color_name)
"%c",
GUI_COLOR_RESET_CHAR);
}
+ else if (string_strcasecmp (color_name, "resetcolor") == 0)
+ {
+ snprintf (color[index_color], sizeof (color[index_color]),
+ "%c%c",
+ GUI_COLOR_COLOR_CHAR,
+ GUI_COLOR_RESET_CHAR);
+ }
else if (string_strcasecmp (color_name, "bold") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
@@ -521,6 +533,9 @@ gui_color_decode (const char *string, const char *replacement)
break;
}
break;
+ case GUI_COLOR_RESET_CHAR:
+ ptr_string++;
+ break;
default:
if (isdigit (ptr_string[0]) && isdigit (ptr_string[1]))
ptr_string += 2;
diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h
index b78cfe4b0..5b87e2a55 100644
--- a/src/gui/gui-color.h
+++ b/src/gui/gui-color.h
@@ -98,6 +98,7 @@ enum t_gui_color_enum
#define GUI_COLOR_EXTENDED_REVERSE_CHAR '!'
#define GUI_COLOR_EXTENDED_ITALIC_CHAR '/'
#define GUI_COLOR_EXTENDED_UNDERLINE_CHAR '_'
+#define GUI_COLOR_EXTENDED_KEEPATTR_CHAR '|'
/* color codes specific to bars */
#define GUI_COLOR_BAR_CHAR 'b'
@@ -115,6 +116,7 @@ enum t_gui_color_enum
#define GUI_COLOR_EXTENDED_REVERSE_FLAG 0x0400000
#define GUI_COLOR_EXTENDED_ITALIC_FLAG 0x0800000
#define GUI_COLOR_EXTENDED_UNDERLINE_FLAG 0x1000000
+#define GUI_COLOR_EXTENDED_KEEPATTR_FLAG 0x2000000
#define GUI_COLOR_EXTENDED_MASK 0x00FFFFF
#define GUI_COLOR_EXTENDED_MAX 99999