mirror of
https://github.com/weechat/weechat.git
synced 2026-07-06 17:53:13 +02:00
core: add color attribute "|" and value "resetcolor" for function weechat_color in plugin API (bug #34550)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -247,6 +247,17 @@ gui_window_reset_style (WINDOW *window, int weechat_color)
|
||||
gui_color[weechat_color]->attributes);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -176,14 +176,14 @@ irc_color_decode (const char *string, int keep_colors)
|
||||
}
|
||||
}
|
||||
snprintf (str_color, sizeof (str_color),
|
||||
"%s%s%s",
|
||||
"|%s%s%s",
|
||||
(fg >= 0) ? irc_color_to_weechat[fg] : "",
|
||||
(bg >= 0) ? "," : "",
|
||||
(bg >= 0) ? irc_color_to_weechat[bg] : "");
|
||||
strcat ((char *)out, weechat_color(str_color));
|
||||
}
|
||||
else
|
||||
strcat ((char *)out, weechat_color("reset"));
|
||||
strcat ((char *)out, weechat_color("resetcolor"));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user