mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 17:23:15 +02:00
Dynamically allocate color pairs
This commit introduces major changes in 256 colors support: - extended colors can be used without being added with command "/color add" - background color is now allowed for nick colors (using slash separator)
This commit is contained in:
@@ -156,8 +156,8 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
int hide_chars_if_scrolling)
|
||||
{
|
||||
int weechat_color, x_with_hidden, size_on_screen, fg, bg, low_char, hidden;
|
||||
int pair, rc;
|
||||
char str_fg[3], str_bg[3], str_pair[6], utf_char[16], *next_char, *output;
|
||||
int pair;
|
||||
char str_fg[6], str_bg[6], str_pair[6], utf_char[16], *next_char, *output;
|
||||
char *error;
|
||||
|
||||
if (!string || !string[0])
|
||||
@@ -185,56 +185,150 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_FG_CHAR: /* fg color */
|
||||
if (string[1] && string[2])
|
||||
if (string[1] == GUI_COLOR_PAIR_CHAR)
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
rc = sscanf (str_fg, "%d", &fg);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg);
|
||||
memcpy (str_fg, string + 2, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg | GUI_COLOR_PAIR_FLAG);
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg);
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_BG_CHAR: /* bg color */
|
||||
if (string[1] && string[2])
|
||||
if (string[1] == GUI_COLOR_PAIR_CHAR)
|
||||
{
|
||||
str_bg[0] = string[1];
|
||||
str_bg[1] = string[2];
|
||||
str_bg[2] = '\0';
|
||||
rc = sscanf (str_bg, "%d", &bg);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bg);
|
||||
memcpy (str_bg, string + 2, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bg | GUI_COLOR_PAIR_FLAG);
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_bg[0] = string[1];
|
||||
str_bg[1] = string[2];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
bg);
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
|
||||
if (string[1] && string[2] && (string[3] == ',')
|
||||
&& string[4] && string[5])
|
||||
str_fg[0] = '\0';
|
||||
str_bg[0] = '\0';
|
||||
fg = -1;
|
||||
bg = -1;
|
||||
if (string[1] == GUI_COLOR_PAIR_CHAR)
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
str_bg[0] = string[4];
|
||||
str_bg[1] = string[5];
|
||||
str_bg[2] = '\0';
|
||||
rc = sscanf (str_fg, "%d", &fg);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
rc = sscanf (str_bg, "%d", &bg);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
memcpy (str_fg, string + 2, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
else
|
||||
fg |= GUI_COLOR_PAIR_FLAG;
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
string += 3;
|
||||
}
|
||||
}
|
||||
if (str_fg[0] && (string[0] == ','))
|
||||
{
|
||||
string++;
|
||||
if (string[0] == GUI_COLOR_PAIR_CHAR)
|
||||
{
|
||||
if (string[1] && string[2] && string[3]
|
||||
&& string[4] && string[5])
|
||||
{
|
||||
gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg, bg);
|
||||
memcpy (str_bg, string + 1, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
else
|
||||
bg |= GUI_COLOR_PAIR_FLAG;
|
||||
string += 6;
|
||||
}
|
||||
}
|
||||
string += 6;
|
||||
else
|
||||
{
|
||||
if (string[0] && string[1])
|
||||
{
|
||||
str_bg[0] = string[0];
|
||||
str_bg[1] = string[1];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
string += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((fg >= 0) && (bg >= 0))
|
||||
{
|
||||
gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
fg, bg);
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_PAIR_CHAR: /* pair number */
|
||||
@@ -303,8 +397,9 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
|
||||
str_fg[0] = string[0];
|
||||
str_fg[1] = string[1];
|
||||
str_fg[2] = '\0';
|
||||
rc = sscanf (str_fg, "%d", &weechat_color);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
error = NULL;
|
||||
weechat_color = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_weechat_color (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
|
||||
weechat_color);
|
||||
@@ -500,6 +595,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
if (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_SIZE]) == 0)
|
||||
gui_bar_window_set_current_size (bar_window, window, 1);
|
||||
gui_window_clear (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]));
|
||||
}
|
||||
else
|
||||
@@ -554,6 +650,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
}
|
||||
|
||||
gui_window_clear (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]));
|
||||
x = 0;
|
||||
y = 0;
|
||||
@@ -714,6 +811,7 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window,
|
||||
if (CONFIG_INTEGER(bar_window->bar->options[GUI_BAR_OPTION_SIZE]) == 0)
|
||||
gui_bar_window_set_current_size (bar_window, window, 1);
|
||||
gui_window_clear (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]));
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ gui_chat_string_next_char (struct t_gui_window *window,
|
||||
const unsigned char *string, int apply_style)
|
||||
{
|
||||
char str_fg[3], str_bg[3], str_pair[6], *error;
|
||||
int weechat_color, fg, bg, pair, rc;
|
||||
int weechat_color, fg, bg, pair;
|
||||
|
||||
while (string[0])
|
||||
{
|
||||
@@ -196,65 +196,174 @@ gui_chat_string_next_char (struct t_gui_window *window,
|
||||
switch (string[0])
|
||||
{
|
||||
case GUI_COLOR_FG_CHAR: /* fg color */
|
||||
if (string[1] && string[2])
|
||||
if (string[1] == GUI_COLOR_PAIR_CHAR)
|
||||
{
|
||||
if (apply_style)
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
rc = sscanf (str_fg, "%d", &fg);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
if (apply_style)
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
fg);
|
||||
memcpy (str_fg, string + 2, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
fg | GUI_COLOR_PAIR_FLAG);
|
||||
}
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_fg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
fg);
|
||||
}
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_BG_CHAR: /* bg color */
|
||||
if (string[1] && string[2])
|
||||
if (string[1] == GUI_COLOR_PAIR_CHAR)
|
||||
{
|
||||
if (apply_style)
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
str_bg[0] = string[1];
|
||||
str_bg[1] = string[2];
|
||||
str_bg[2] = '\0';
|
||||
rc = sscanf (str_bg, "%d", &bg);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
if (apply_style)
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
bg);
|
||||
memcpy (str_bg, string + 2, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
bg | GUI_COLOR_PAIR_FLAG);
|
||||
}
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
str_bg[0] = string[1];
|
||||
str_bg[1] = string[2];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_custom_color_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
bg);
|
||||
}
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */
|
||||
if (string[1] && string[2] && (string[3] == ',')
|
||||
&& string[4] && string[5])
|
||||
str_fg[0] = '\0';
|
||||
str_bg[0] = '\0';
|
||||
fg = -1;
|
||||
bg = -1;
|
||||
if (string[1] == GUI_COLOR_PAIR_CHAR)
|
||||
{
|
||||
if (apply_style)
|
||||
if (string[2] && string[3] && string[4]
|
||||
&& string[5] && string[6])
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
str_bg[0] = string[4];
|
||||
str_bg[1] = string[5];
|
||||
str_bg[2] = '\0';
|
||||
rc = sscanf (str_fg, "%d", &fg);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
if (apply_style)
|
||||
{
|
||||
rc = sscanf (str_bg, "%d", &bg);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
memcpy (str_fg, string + 2, 5);
|
||||
str_fg[5] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
else
|
||||
fg |= GUI_COLOR_PAIR_FLAG;
|
||||
}
|
||||
string += 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string[1] && string[2])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
str_fg[0] = string[1];
|
||||
str_fg[1] = string[2];
|
||||
str_fg[2] = '\0';
|
||||
error = NULL;
|
||||
fg = (int)strtol (str_fg, &error, 10);
|
||||
if (!error || error[0])
|
||||
fg = -1;
|
||||
}
|
||||
string += 3;
|
||||
}
|
||||
}
|
||||
if (string[0] == ',')
|
||||
{
|
||||
string++;
|
||||
if (string[0] == GUI_COLOR_PAIR_CHAR)
|
||||
{
|
||||
if (string[1] && string[2] && string[3]
|
||||
&& string[4] && string[5])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
gui_window_set_custom_color_fg_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
fg, bg);
|
||||
memcpy (str_bg, string + 1, 5);
|
||||
str_bg[5] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
else
|
||||
bg |= GUI_COLOR_PAIR_FLAG;
|
||||
}
|
||||
string += 6;
|
||||
}
|
||||
}
|
||||
string += 6;
|
||||
else
|
||||
{
|
||||
if (string[0] && string[1])
|
||||
{
|
||||
if (apply_style)
|
||||
{
|
||||
str_bg[0] = string[0];
|
||||
str_bg[1] = string[1];
|
||||
str_bg[2] = '\0';
|
||||
error = NULL;
|
||||
bg = (int)strtol (str_bg, &error, 10);
|
||||
if (!error || error[0])
|
||||
bg = -1;
|
||||
}
|
||||
string += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (apply_style && (fg >= 0) && (bg >= 0))
|
||||
{
|
||||
gui_window_set_custom_color_fg_bg (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
fg, bg);
|
||||
}
|
||||
break;
|
||||
case GUI_COLOR_PAIR_CHAR: /* pair number */
|
||||
@@ -301,8 +410,9 @@ gui_chat_string_next_char (struct t_gui_window *window,
|
||||
str_fg[0] = string[0];
|
||||
str_fg[1] = string[1];
|
||||
str_fg[2] = '\0';
|
||||
rc = sscanf (str_fg, "%d", &weechat_color);
|
||||
if ((rc != EOF) && (rc >= 1))
|
||||
error = NULL;
|
||||
weechat_color = (int)strtol (str_fg, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat,
|
||||
weechat_color);
|
||||
@@ -1028,7 +1138,7 @@ gui_chat_display_line_y (struct t_gui_window *window, struct t_gui_line *line,
|
||||
if (gui_chat_display_word_raw (window, line->data->message,
|
||||
window->win_chat_width, 1) < window->win_chat_width)
|
||||
{
|
||||
gui_window_clrtoeol_with_current_bg (GUI_WINDOW_OBJECTS(window)->win_chat);
|
||||
gui_window_clrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+702
-340
File diff suppressed because it is too large
Load Diff
@@ -224,6 +224,13 @@ gui_main_refreshs ()
|
||||
struct t_gui_window *ptr_win;
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
struct t_gui_bar *ptr_bar;
|
||||
|
||||
/* refresh color buffer if needed */
|
||||
if (gui_color_buffer_refresh_needed)
|
||||
{
|
||||
gui_color_buffer_display ();
|
||||
gui_color_buffer_refresh_needed = 0;
|
||||
}
|
||||
|
||||
/* refresh window if needed */
|
||||
if (gui_window_refresh_needed)
|
||||
|
||||
@@ -205,22 +205,24 @@ gui_window_clear_weechat (WINDOW *window, int weechat_color)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_clear (WINDOW *window, int bg)
|
||||
gui_window_clear (WINDOW *window, int fg, int bg)
|
||||
{
|
||||
int color;
|
||||
|
||||
if (!gui_ok)
|
||||
return;
|
||||
|
||||
if ((bg >= 0) && (bg < GUI_CURSES_NUM_WEECHAT_COLORS))
|
||||
{
|
||||
color = gui_weechat_colors[bg].background;
|
||||
wbkgdset (window,
|
||||
' ' | COLOR_PAIR (((color == -1) || (color == 99)) ?
|
||||
gui_color_last_pair : (color * gui_color_num_bg) + 1));
|
||||
werase (window);
|
||||
wmove (window, 0, 0);
|
||||
}
|
||||
|
||||
if ((fg > 0) && (fg & GUI_COLOR_PAIR_FLAG))
|
||||
fg &= GUI_COLOR_PAIR_MASK;
|
||||
else
|
||||
fg = gui_weechat_colors[fg].foreground;
|
||||
|
||||
if ((bg > 0) && (bg & GUI_COLOR_PAIR_FLAG))
|
||||
bg &= GUI_COLOR_PAIR_MASK;
|
||||
else
|
||||
bg = gui_weechat_colors[bg].background;
|
||||
|
||||
wbkgdset (window, ' ' | COLOR_PAIR (gui_color_get_pair (fg, bg)));
|
||||
werase (window);
|
||||
wmove (window, 0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -273,17 +275,7 @@ gui_window_set_color (WINDOW *window, int fg, int bg)
|
||||
window_current_style_fg = fg;
|
||||
window_current_style_bg = bg;
|
||||
|
||||
if (((fg == -1) || (fg == 99))
|
||||
&& ((bg == -1) || (bg == 99)))
|
||||
wattron (window, COLOR_PAIR(gui_color_last_pair));
|
||||
else
|
||||
{
|
||||
if ((fg == -1) || (fg == 99))
|
||||
fg = COLOR_WHITE;
|
||||
if ((bg == -1) || (bg == 99))
|
||||
bg = 0;
|
||||
wattron (window, COLOR_PAIR((bg * gui_color_num_bg) + fg + 1));
|
||||
}
|
||||
wattron (window, COLOR_PAIR(gui_color_get_pair (fg, bg)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -293,21 +285,19 @@ gui_window_set_color (WINDOW *window, int fg, int bg)
|
||||
void
|
||||
gui_window_set_weechat_color (WINDOW *window, int num_color)
|
||||
{
|
||||
int fg, bg;
|
||||
|
||||
if ((num_color >= 0) && (num_color < GUI_COLOR_NUM_COLORS))
|
||||
{
|
||||
gui_window_reset_style (window, num_color);
|
||||
wattron (window, gui_color[num_color]->attributes);
|
||||
if ((gui_color[num_color]->foreground > 0)
|
||||
&& (gui_color[num_color]->foreground & GUI_COLOR_PAIR_FLAG))
|
||||
{
|
||||
wattron (window, COLOR_PAIR(gui_color[num_color]->foreground & GUI_COLOR_PAIR_MASK));
|
||||
}
|
||||
else
|
||||
{
|
||||
gui_window_set_color (window,
|
||||
gui_color[num_color]->foreground,
|
||||
gui_color[num_color]->background);
|
||||
}
|
||||
fg = gui_color[num_color]->foreground;
|
||||
bg = gui_color[num_color]->background;
|
||||
if ((fg > 0) && (fg & GUI_COLOR_PAIR_FLAG))
|
||||
fg &= GUI_COLOR_PAIR_MASK;
|
||||
if ((bg > 0) && (bg & GUI_COLOR_PAIR_FLAG))
|
||||
bg &= GUI_COLOR_PAIR_MASK;
|
||||
gui_window_set_color (window, fg, bg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,30 +309,27 @@ gui_window_set_weechat_color (WINDOW *window, int num_color)
|
||||
void
|
||||
gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg)
|
||||
{
|
||||
if ((fg >= 0) && (fg < GUI_CURSES_NUM_WEECHAT_COLORS)
|
||||
&& (bg >= 0) && (bg < GUI_CURSES_NUM_WEECHAT_COLORS))
|
||||
if ((fg >= 0) && (bg >= 0))
|
||||
{
|
||||
gui_window_remove_color_style (window, A_BOLD);
|
||||
wattron (window, gui_weechat_colors[fg].attributes);
|
||||
gui_window_set_color (window,
|
||||
gui_weechat_colors[fg].foreground,
|
||||
(gui_color_num_bg > 8) ?
|
||||
gui_weechat_colors[bg].background : gui_weechat_colors[bg].foreground);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_set_custom_color_pair: set a custom color for a window
|
||||
* (pair number)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_set_custom_color_pair (WINDOW *window, int pair)
|
||||
{
|
||||
if ((pair >= 0) && (pair <= gui_color_last_pair))
|
||||
{
|
||||
gui_window_remove_color_style (window, A_BOLD);
|
||||
wattron (window, COLOR_PAIR(pair));
|
||||
|
||||
if ((fg > 0) && (fg & GUI_COLOR_PAIR_FLAG))
|
||||
fg &= GUI_COLOR_PAIR_MASK;
|
||||
else
|
||||
{
|
||||
wattron (window, gui_weechat_colors[fg].attributes);
|
||||
fg = gui_weechat_colors[fg].foreground;
|
||||
}
|
||||
|
||||
if ((bg > 0) && (bg & GUI_COLOR_PAIR_FLAG))
|
||||
bg &= GUI_COLOR_PAIR_MASK;
|
||||
else
|
||||
{
|
||||
bg = (gui_color_num_bg > 8) ?
|
||||
gui_weechat_colors[bg].background : gui_weechat_colors[bg].foreground;
|
||||
}
|
||||
|
||||
gui_window_set_color (window, fg, bg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,16 +342,17 @@ void
|
||||
gui_window_set_custom_color_fg (WINDOW *window, int fg)
|
||||
{
|
||||
int current_bg;
|
||||
|
||||
|
||||
if (fg >= 0)
|
||||
{
|
||||
if (fg & GUI_COLOR_PAIR_FLAG)
|
||||
current_bg = window_current_style_bg;
|
||||
|
||||
if ((fg > 0) && (fg & GUI_COLOR_PAIR_FLAG))
|
||||
{
|
||||
gui_window_set_custom_color_pair (window, fg & GUI_COLOR_PAIR_MASK);
|
||||
gui_window_set_color (window, fg & GUI_COLOR_PAIR_MASK, current_bg);
|
||||
}
|
||||
else if (fg < GUI_CURSES_NUM_WEECHAT_COLORS)
|
||||
{
|
||||
current_bg = window_current_style_bg;
|
||||
gui_window_remove_color_style (window, A_BOLD);
|
||||
gui_window_set_color_style (window, gui_weechat_colors[fg].attributes);
|
||||
gui_window_set_color (window,
|
||||
@@ -386,14 +374,15 @@ gui_window_set_custom_color_bg (WINDOW *window, int bg)
|
||||
|
||||
if (bg >= 0)
|
||||
{
|
||||
if (bg & GUI_COLOR_PAIR_FLAG)
|
||||
current_attr = window_current_style_attr;
|
||||
current_fg = window_current_style_fg;
|
||||
|
||||
if ((bg > 0) && (bg & GUI_COLOR_PAIR_FLAG))
|
||||
{
|
||||
gui_window_set_custom_color_pair (window, bg & GUI_COLOR_PAIR_MASK);
|
||||
gui_window_set_color (window, current_fg, bg & GUI_COLOR_PAIR_MASK);
|
||||
}
|
||||
else if (bg < GUI_CURSES_NUM_WEECHAT_COLORS)
|
||||
{
|
||||
current_attr = window_current_style_attr;
|
||||
current_fg = window_current_style_fg;
|
||||
gui_window_set_color_style (window, current_attr);
|
||||
gui_window_set_color (window, current_fg,
|
||||
(gui_color_num_bg > 8) ?
|
||||
@@ -403,15 +392,30 @@ gui_window_set_custom_color_bg (WINDOW *window, int bg)
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_clrtoeol_with_current_bg: clear until end of line with current bg
|
||||
* gui_window_set_custom_color_pair: set a custom color for a window
|
||||
* (pair number)
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_clrtoeol_with_current_bg (WINDOW *window)
|
||||
gui_window_set_custom_color_pair (WINDOW *window, int pair)
|
||||
{
|
||||
if ((pair >= 0) && (pair <= gui_color_num_pairs))
|
||||
{
|
||||
gui_window_remove_color_style (window, A_BOLD);
|
||||
wattron (window, COLOR_PAIR(pair));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* gui_window_clrtoeol: clear until end of line with current background
|
||||
*/
|
||||
|
||||
void
|
||||
gui_window_clrtoeol (WINDOW *window)
|
||||
{
|
||||
wbkgdset (window,
|
||||
' ' | COLOR_PAIR ((window_current_style_bg < 0) ?
|
||||
gui_color_last_pair : (window_current_style_bg * gui_color_num_bg) + 1));
|
||||
' ' | COLOR_PAIR (gui_color_get_pair (window_current_style_fg,
|
||||
window_current_style_bg)));
|
||||
wclrtoeol (window);
|
||||
}
|
||||
|
||||
@@ -1526,8 +1530,6 @@ gui_window_term_display_infos ()
|
||||
gui_chat_printf (NULL, _("Terminal infos:"));
|
||||
gui_chat_printf (NULL, _(" TERM='%s', size: %dx%d"),
|
||||
getenv("TERM"), gui_term_cols, gui_term_lines);
|
||||
gui_chat_printf (NULL, _(" %d colors available, %d pairs"),
|
||||
COLORS, COLOR_PAIRS);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -57,10 +57,12 @@ struct t_gui_bar_window_curses_objects
|
||||
|
||||
extern int gui_term_cols, gui_term_lines;
|
||||
extern struct t_gui_color gui_weechat_colors[];
|
||||
extern int gui_color_last_pair;
|
||||
extern int gui_color_num_pairs;
|
||||
extern int gui_color_num_bg;
|
||||
extern int gui_color_buffer_refresh_needed;
|
||||
|
||||
/* color functions */
|
||||
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 ();
|
||||
extern void gui_color_init ();
|
||||
@@ -79,7 +81,7 @@ extern int gui_keyboard_read_cb (void *data, int fd);
|
||||
extern void gui_window_read_terminal_size ();
|
||||
extern void gui_window_redraw_buffer (struct t_gui_buffer *buffer);
|
||||
extern int gui_window_get_hline_char ();
|
||||
extern void gui_window_clear (WINDOW *window, int bg);
|
||||
extern void gui_window_clear (WINDOW *window, int fg, int bg);
|
||||
extern void gui_window_reset_style (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);
|
||||
@@ -89,7 +91,7 @@ extern void gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg);
|
||||
extern void gui_window_set_custom_color_pair (WINDOW *window, int pair);
|
||||
extern void gui_window_set_custom_color_fg (WINDOW *window, int fg);
|
||||
extern void gui_window_set_custom_color_bg (WINDOW *window, int bg);
|
||||
extern void gui_window_clrtoeol_with_current_bg (WINDOW *window);
|
||||
extern void gui_window_clrtoeol (WINDOW *window);
|
||||
extern void gui_window_set_title (const char *title);
|
||||
|
||||
#endif /* __WEECHAT_GUI_CURSES_H */
|
||||
|
||||
Reference in New Issue
Block a user