1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 15:26:37 +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:
Sebastien Helleu
2011-01-31 19:03:30 +01:00
parent 773effbb3a
commit ccb08945a1
49 changed files with 2134 additions and 1974 deletions
+135 -37
View File
@@ -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]));
}
+150 -40
View File
@@ -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);
}
}
File diff suppressed because it is too large Load Diff
+7
View File
@@ -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)
+73 -71
View File
@@ -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);
}
/*
+5 -3
View File
@@ -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 */
-11
View File
@@ -147,17 +147,6 @@ void
gui_chat_set_color (struct t_gui_window *window, int fg, int bg)
{
/* TODO: write this function for Gtk */
/*if (((fg == -1) || (fg == 99))
&& ((bg == -1) || (bg == 99)))
wattron (window->win_chat, COLOR_PAIR(63));
else
{
if ((fg == -1) || (fg == 99))
fg = WEECHAT_COLOR_WHITE;
if ((bg == -1) || (bg == 99))
bg = 0;
wattron (window->win_chat, COLOR_PAIR((bg * 8) + fg));
}*/
(void) window;
(void) fg;
(void) bg;
+72 -75
View File
@@ -132,15 +132,40 @@ gui_color_get_weechat_colors_number ()
}
/*
* gui_color_get_last_pair: get last pair number
* gui_color_get_term_colors: get number of colors supported by terminal
*/
int
gui_color_get_last_pair ()
gui_color_get_term_colors ()
{
return 0;
}
/*
* gui_color_get_pair: get a pair with given foreground/background colors
*/
int
gui_color_get_pair (int fg, int bg)
{
(void) fg;
(void) bg;
return 0;
}
/*
* gui_color_weechat_get_pair: get color pair with a WeeChat color number
*/
int
gui_color_weechat_get_pair (int weechat_color)
{
(void) weechat_color;
return 0;
}
/*
* gui_color_get_name: get color name
*/
@@ -151,53 +176,6 @@ gui_color_get_name (int num_color)
return gui_weechat_colors[num_color].string;
}
/*
* gui_color_get_pair: get color pair with a WeeChat color number
*/
int
gui_color_get_pair (int num_color)
{
int fg, bg;
if ((num_color < 0) || (num_color > GUI_COLOR_NUM_COLORS - 1))
return WEECHAT_COLOR_WHITE;
fg = gui_color[num_color]->foreground;
bg = gui_color[num_color]->background;
if (((fg == -1) || (fg == 99))
&& ((bg == -1) || (bg == 99)))
return 63;
if ((fg == -1) || (fg == 99))
fg = WEECHAT_COLOR_WHITE;
if ((bg == -1) || (bg == 99))
bg = 0;
return (bg * 8) + fg;
}
/*
* gui_color_init_pair: init a color pair
*/
void
gui_color_init_pair (int number)
{
/* This function does nothing in Gtk GUI */
(void) number;
}
/*
* gui_color_init_pairs: init color pairs
*/
void
gui_color_init_pairs ()
{
/* This function does nothing in Gtk GUI */
}
/*
* gui_color_init_weechat: init WeeChat colors
*/
@@ -230,32 +208,6 @@ gui_color_rebuild_weechat ()
gui_color_init_weechat ();
}
/*
* gui_color_pre_init: pre-init colors
*/
void
gui_color_pre_init ()
{
int i;
for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
{
gui_color[i] = NULL;
}
}
/*
* gui_color_init: init GUI colors
*/
void
gui_color_init ()
{
gui_color_init_pairs ();
gui_color_init_weechat ();
}
/*
* gui_color_display_terminal_colors: display terminal colors
* This is called by command line option
@@ -288,6 +240,16 @@ gui_color_switch_colors ()
/* This function does nothing in Gtk GUI */
}
/*
* gui_color_reset_pairs: reset all color pairs
*/
void
gui_color_reset_pairs ()
{
/* This function does nothing in Gtk GUI */
}
/*
* gui_color_buffer_assign: assign color buffer to pointer if it is not yet set
*/
@@ -343,6 +305,41 @@ gui_color_palette_free (struct t_gui_color_palette *color_palette)
(void) color_palette;
}
/*
* gui_color_pre_init: pre-init colors
*/
void
gui_color_pre_init ()
{
int i;
for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
{
gui_color[i] = NULL;
}
}
/*
* gui_color_init: init GUI colors
*/
void
gui_color_init ()
{
gui_color_init_weechat ();
}
/*
* gui_color_dump: dump colors
*/
void
gui_color_dump ()
{
/* This function does nothing in Gtk GUI */
}
/*
* gui_color_end: end GUI colors
*/
+1 -1
View File
@@ -88,7 +88,7 @@ extern GtkWidget *gui_gtk_entry_input;
extern GtkWidget *gui_gtk_label1;
/* color functions */
extern int gui_color_get_pair (int num_color);
extern int gui_color_get_pair (int fg, int bg);
extern void gui_color_pre_init ();
extern void gui_color_init ();
extern void gui_color_end ();
+2 -2
View File
@@ -888,7 +888,7 @@ void
gui_buffer_set_nicklist (struct t_gui_buffer *buffer, int nicklist)
{
buffer->nicklist = (nicklist) ? 1 : 0;
gui_window_refresh_windows ();
gui_window_ask_refresh (1);
}
/*
@@ -913,7 +913,7 @@ gui_buffer_set_nicklist_display_groups (struct t_gui_buffer *buffer,
buffer->nicklist_display_groups = (display_groups) ? 1 : 0;
buffer->nicklist_visible_count = 0;
gui_nicklist_compute_visible_count (buffer, buffer->nicklist_root);
gui_window_refresh_windows ();
gui_window_ask_refresh (1);
}
/*
+178 -109
View File
@@ -91,10 +91,11 @@ gui_color_search_config (const char *color_name)
const char *
gui_color_get_custom (const char *color_name)
{
int fg, bg, pair;
int fg, bg, fg_pair, bg_pair, pair;
static char color[32][16];
static int index_color = 0;
char *pos_comma, *str_fg, *pos_bg, *error;
char color_fg[32], color_bg[32];
char *pos_delim, *str_fg, *pos_bg, *error;
/* attribute or other color name (GUI dependent) */
index_color = (index_color + 1) % 32;
@@ -106,64 +107,64 @@ gui_color_get_custom (const char *color_name)
if (string_strcasecmp (color_name, "reset") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s",
GUI_COLOR_RESET_STR);
"%c",
GUI_COLOR_RESET_CHAR);
}
else if (string_strcasecmp (color_name, "bold") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s",
GUI_COLOR_SET_WEECHAT_STR,
GUI_COLOR_ATTR_BOLD_STR);
"%c%c",
GUI_COLOR_SET_WEECHAT_CHAR,
GUI_COLOR_ATTR_BOLD_CHAR);
}
else if (string_strcasecmp (color_name, "-bold") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s",
GUI_COLOR_REMOVE_WEECHAT_STR,
GUI_COLOR_ATTR_BOLD_STR);
"%c%c",
GUI_COLOR_REMOVE_WEECHAT_CHAR,
GUI_COLOR_ATTR_BOLD_CHAR);
}
else if (string_strcasecmp (color_name, "reverse") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s",
GUI_COLOR_SET_WEECHAT_STR,
GUI_COLOR_ATTR_REVERSE_STR);
"%c%c",
GUI_COLOR_SET_WEECHAT_CHAR,
GUI_COLOR_ATTR_REVERSE_CHAR);
}
else if (string_strcasecmp (color_name, "-reverse") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s",
GUI_COLOR_REMOVE_WEECHAT_STR,
GUI_COLOR_ATTR_REVERSE_STR);
"%c%c",
GUI_COLOR_REMOVE_WEECHAT_CHAR,
GUI_COLOR_ATTR_REVERSE_CHAR);
}
else if (string_strcasecmp (color_name, "italic") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s",
GUI_COLOR_SET_WEECHAT_STR,
GUI_COLOR_ATTR_ITALIC_STR);
"%c%c",
GUI_COLOR_SET_WEECHAT_CHAR,
GUI_COLOR_ATTR_ITALIC_CHAR);
}
else if (string_strcasecmp (color_name, "-italic") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s",
GUI_COLOR_REMOVE_WEECHAT_STR,
GUI_COLOR_ATTR_ITALIC_STR);
"%c%c",
GUI_COLOR_REMOVE_WEECHAT_CHAR,
GUI_COLOR_ATTR_ITALIC_CHAR);
}
else if (string_strcasecmp (color_name, "underline") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s",
GUI_COLOR_SET_WEECHAT_STR,
GUI_COLOR_ATTR_UNDERLINE_STR);
"%c%c",
GUI_COLOR_SET_WEECHAT_CHAR,
GUI_COLOR_ATTR_UNDERLINE_CHAR);
}
else if (string_strcasecmp (color_name, "-underline") == 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s",
GUI_COLOR_REMOVE_WEECHAT_STR,
GUI_COLOR_ATTR_UNDERLINE_STR);
"%c%c",
GUI_COLOR_REMOVE_WEECHAT_CHAR,
GUI_COLOR_ATTR_UNDERLINE_CHAR);
}
else if (string_strcasecmp (color_name, "bar_fg") == 0)
{
@@ -192,86 +193,121 @@ gui_color_get_custom (const char *color_name)
else
{
/* custom color name (GUI dependent) */
pair = gui_color_palette_get_alias (color_name);
if (pair >= 0)
pos_delim = strchr (color_name, ',');
if (!pos_delim)
pos_delim = strchr (color_name, '/');
if (pos_delim)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%05d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_PAIR_STR,
pair);
if (pos_delim == color_name)
str_fg = NULL;
else
str_fg = string_strndup (color_name, pos_delim - color_name);
pos_bg = pos_delim + 1;
}
else
{
error = NULL;
pair = (int)strtol (color_name, &error, 10);
if (error && !error[0])
str_fg = strdup (color_name);
pos_bg = NULL;
}
fg_pair = -1;
bg_pair = -1;
fg = -1;
bg = -1;
color_fg[0] = '\0';
color_bg[0] = '\0';
if (str_fg)
{
fg_pair = gui_color_palette_get_alias (str_fg);
if (fg_pair < 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%05d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_PAIR_STR,
pair);
}
else
{
pos_comma = strchr (color_name, ',');
if (pos_comma)
error = NULL;
pair = (int)strtol (str_fg, &error, 10);
if (error && !error[0])
{
if (pos_comma == color_name)
str_fg = NULL;
else
str_fg = string_strndup (color_name, pos_comma - color_name);
pos_bg = pos_comma + 1;
fg_pair = pair;
if (fg_pair < 0)
fg_pair = 0;
else if (fg_pair > 99999)
fg_pair = 99999;
}
else
{
str_fg = strdup (color_name);
pos_bg = NULL;
}
if (str_fg && pos_bg)
{
fg = gui_color_search (str_fg);
bg = gui_color_search (pos_bg);
if ((fg >= 0) && (bg >= 0))
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%02d,%02d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_FG_BG_STR,
fg, bg);
}
}
else if (str_fg && !pos_bg)
{
fg = gui_color_search (str_fg);
if (fg >= 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%02d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_FG_STR,
fg);
}
}
else if (!str_fg && pos_bg)
{
bg = gui_color_search (pos_bg);
if (bg >= 0)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%02d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_BG_STR,
bg);
}
}
if (str_fg)
free (str_fg);
}
}
if (pos_bg)
{
bg_pair = gui_color_palette_get_alias (pos_bg);
if (bg_pair < 0)
{
error = NULL;
pair = (int)strtol (pos_bg, &error, 10);
if (error && !error[0])
{
bg_pair = pair;
if (bg_pair < 0)
bg_pair = 0;
else if (bg_pair > 99999)
bg_pair = 99999;
}
else
bg = gui_color_search (pos_bg);
}
}
if (fg_pair >= 0)
{
snprintf (color_fg, sizeof (color_fg), "%c%05d",
GUI_COLOR_PAIR_CHAR,
fg_pair);
}
else if (fg >= 0)
{
snprintf (color_fg, sizeof (color_fg), "%02d",
fg);
}
if (bg_pair >= 0)
{
snprintf (color_bg, sizeof (color_bg), "%c%05d",
GUI_COLOR_PAIR_CHAR,
bg_pair);
}
else if (bg >= 0)
{
snprintf (color_bg, sizeof (color_bg), "%02d",
bg);
}
if (color_fg[0] && color_bg[0])
{
snprintf (color[index_color], sizeof (color[index_color]),
"%c%c%s,%s",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_FG_BG_CHAR,
color_fg,
color_bg);
}
else if (color_fg[0])
{
snprintf (color[index_color], sizeof (color[index_color]),
"%c%c%s",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_FG_CHAR,
color_fg);
}
else if (color_bg[0])
{
snprintf (color[index_color], sizeof (color[index_color]),
"%c%c%s",
GUI_COLOR_COLOR_CHAR,
GUI_COLOR_BG_CHAR,
color_bg);
}
if (str_fg)
free (str_fg);
}
return color[index_color];
@@ -314,13 +350,51 @@ gui_color_decode (const char *string, const char *replacement)
{
case GUI_COLOR_FG_CHAR:
case GUI_COLOR_BG_CHAR:
if (ptr_string[1] && ptr_string[2])
ptr_string += 3;
if (ptr_string[1] == GUI_COLOR_PAIR_CHAR)
{
if (ptr_string[2] && ptr_string[3] && ptr_string[4]
&& ptr_string[5] && ptr_string[6])
{
ptr_string += 7;
}
}
else
{
if (ptr_string[1] && ptr_string[2])
ptr_string += 3;
}
break;
case GUI_COLOR_FG_BG_CHAR:
if (ptr_string[1] && ptr_string[2] && (ptr_string[3] == ',')
&& ptr_string[4] && ptr_string[5])
ptr_string += 6;
if (ptr_string[1] == GUI_COLOR_PAIR_CHAR)
{
if (ptr_string[2] && ptr_string[3] && ptr_string[4]
&& ptr_string[5] && ptr_string[6])
{
ptr_string += 7;
}
}
else
{
if (ptr_string[1] && ptr_string[2])
ptr_string += 3;
}
if (ptr_string[0] == ',')
{
if (ptr_string[1] == GUI_COLOR_PAIR_CHAR)
{
if (ptr_string[2] && ptr_string[3]
&& ptr_string[4] && ptr_string[5]
&& ptr_string[6])
{
ptr_string += 7;
}
}
else
{
if (ptr_string[1] && ptr_string[2])
ptr_string += 3;
}
}
break;
case GUI_COLOR_PAIR_CHAR:
if ((isdigit (ptr_string[1])) && (isdigit (ptr_string[2]))
@@ -582,17 +656,14 @@ gui_color_palette_add (int number, const char *value)
new_color_palette = gui_color_palette_new (number, value);
if (!new_color_palette)
return;
snprintf (str_number, sizeof (str_number), "%d", number);
hashtable_set (gui_color_hash_palette_color,
str_number, new_color_palette);
gui_color_palette_build_aliases ();
if (gui_init_ok)
{
gui_color_init_pair (number);
gui_color_buffer_display ();
}
}
/*
@@ -614,11 +685,9 @@ gui_color_palette_remove (int number)
{
hashtable_remove (gui_color_hash_palette_color, str_number);
gui_color_palette_build_aliases ();
if (gui_init_ok)
{
gui_color_init_pair (number);
gui_color_buffer_display ();
}
}
}
+7 -23
View File
@@ -69,52 +69,36 @@ enum t_gui_color_enum
/* WeeChat internal color attributes (should never be in protocol messages) */
#define GUI_COLOR_COLOR_CHAR '\x19'
#define GUI_COLOR_COLOR_STR "\x19"
#define GUI_COLOR_SET_WEECHAT_CHAR '\x1A'
#define GUI_COLOR_SET_WEECHAT_STR "\x1A"
#define GUI_COLOR_REMOVE_WEECHAT_CHAR '\x1B'
#define GUI_COLOR_REMOVE_WEECHAT_STR "\x1B"
#define GUI_COLOR_RESET_CHAR '\x1C'
#define GUI_COLOR_RESET_STR "\x1C"
#define GUI_COLOR_ATTR_BOLD_CHAR '\x01'
#define GUI_COLOR_ATTR_BOLD_STR "\x01"
#define GUI_COLOR_ATTR_REVERSE_CHAR '\x02'
#define GUI_COLOR_ATTR_REVERSE_STR "\x02"
#define GUI_COLOR_ATTR_ITALIC_CHAR '\x03'
#define GUI_COLOR_ATTR_ITALIC_STR "\x03"
#define GUI_COLOR_ATTR_UNDERLINE_CHAR '\x04'
#define GUI_COLOR_ATTR_UNDERLINE_STR "\x04"
#define GUI_COLOR(color) ((gui_color[color]) ? gui_color[color]->string : "")
#define GUI_NO_COLOR GUI_COLOR_RESET_STR
#define GUI_NO_COLOR "\x1C"
#define GUI_COLOR_CUSTOM_BAR_FG (gui_color_get_custom ("bar_fg"))
#define GUI_COLOR_CUSTOM_BAR_DELIM (gui_color_get_custom ("bar_delim"))
#define GUI_COLOR_CUSTOM_BAR_BG (gui_color_get_custom ("bar_bg"))
/* color codes for chat and bars */
#define GUI_COLOR_FG_CHAR 'F'
#define GUI_COLOR_FG_STR "F"
#define GUI_COLOR_BG_CHAR 'B'
#define GUI_COLOR_BG_STR "B"
#define GUI_COLOR_FG_BG_CHAR '*'
#define GUI_COLOR_FG_BG_STR "*"
#define GUI_COLOR_PAIR_CHAR '@'
#define GUI_COLOR_PAIR_STR "@"
/* color codes specific to bars */
#define GUI_COLOR_BAR_CHAR 'b'
#define GUI_COLOR_BAR_STR "b"
#define GUI_COLOR_BAR_FG_CHAR 'F'
#define GUI_COLOR_BAR_FG_STR "F"
#define GUI_COLOR_BAR_DELIM_CHAR 'D'
#define GUI_COLOR_BAR_DELIM_STR "D"
#define GUI_COLOR_BAR_BG_CHAR 'B'
#define GUI_COLOR_BAR_BG_STR "B"
#define GUI_COLOR_BAR_START_INPUT_CHAR '_'
#define GUI_COLOR_BAR_START_INPUT_STR "_"
#define GUI_COLOR_BAR_START_INPUT_HIDDEN_CHAR '-'
#define GUI_COLOR_BAR_START_INPUT_HIDDEN_STR "-"
#define GUI_COLOR_BAR_MOVE_CURSOR_CHAR '#'
#define GUI_COLOR_BAR_MOVE_CURSOR_STR "#"
#define GUI_COLOR_PAIR_FLAG 0x10000
#define GUI_COLOR_PAIR_MASK 0xFFFF
@@ -134,8 +118,6 @@ struct t_gui_color
struct t_gui_color_palette
{
char *alias; /* alias name for this color pair */
int foreground; /* foreground color */
int background; /* background color */
int r, g, b; /* red/green/blue values for color */
};
@@ -167,7 +149,7 @@ extern int gui_color_assign (int *color, char const *color_name);
extern int gui_color_assign_by_diff (int *color, const char *color_name,
int diff);
extern int gui_color_get_weechat_colors_number ();
extern int gui_color_get_last_pair ();
extern int gui_color_get_term_colors ();
extern const char *gui_color_get_name (int num_color);
extern void gui_color_init_pair (int number);
extern void gui_color_init_pairs ();
@@ -175,11 +157,13 @@ extern void gui_color_init_weechat ();
extern void gui_color_display_terminal_colors ();
extern void gui_color_buffer_display ();
extern void gui_color_switch_colors ();
extern void gui_color_reset_pairs ();
extern void gui_color_buffer_assign ();
extern void gui_color_buffer_open ();
extern void gui_color_palette_build_aliases ();
extern struct t_gui_color_palette *gui_color_palette_new (int number,
const char *value);
extern void gui_color_palette_free (struct t_gui_color_palette *color_palette);
extern void gui_color_dump ();
#endif /* __WEECHAT_GUI_COLOR_H */
-1
View File
@@ -158,7 +158,6 @@ extern void gui_window_scroll_up (struct t_gui_window *window);
extern void gui_window_scroll_down (struct t_gui_window *window);
extern void gui_window_scroll_top (struct t_gui_window *window);
extern void gui_window_scroll_bottom (struct t_gui_window *window);
extern void gui_window_refresh_windows ();
extern struct t_gui_window *gui_window_split_horizontal (struct t_gui_window *window,
int percentage);
extern struct t_gui_window *gui_window_split_vertical (struct t_gui_window *window,