1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 01:33:12 +02:00

Allow use of color pair number in color options and in API function "weechat_color"

This commit is contained in:
Sebastien Helleu
2010-12-17 09:54:46 +01:00
parent f2c9961a21
commit 4043ca3d38
8 changed files with 183 additions and 64 deletions
+1 -2
View File
@@ -1286,8 +1286,7 @@ config_file_option_set (struct t_config_option *option, const char *value,
}
else
{
gui_color_assign (&value_int, value);
if ((value_int >= 0) && (value_int <= num_colors - 1))
if (gui_color_assign (&value_int, value))
new_value_ok = 1;
}
if (new_value_ok)
+20 -1
View File
@@ -156,7 +156,9 @@ 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;
char str_fg[3], str_bg[3], utf_char[16], *next_char, *output;
int pair;
char str_fg[3], str_bg[3], str_pair[6], utf_char[16], *next_char, *output;
char *error;
if (!string || !string[0])
return 1;
@@ -223,6 +225,23 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window,
string += 6;
}
break;
case GUI_COLOR_PAIR_CHAR: /* pair number */
if ((isdigit (string[1])) && (isdigit (string[2]))
&& (isdigit (string[3])) && (isdigit (string[4]))
&& (isdigit (string[5])))
{
memcpy (str_pair, string + 1, 5);
str_pair[5] = '\0';
error = NULL;
pair = (int)strtol (str_pair, &error, 10);
if (error && !error[0])
{
gui_window_set_custom_color_pair (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar,
pair);
}
string += 6;
}
break;
case GUI_COLOR_BAR_CHAR: /* bar color */
switch (string[1])
{
+22 -2
View File
@@ -179,8 +179,8 @@ char *
gui_chat_string_next_char (struct t_gui_window *window,
const unsigned char *string, int apply_style)
{
char str_fg[3], str_bg[3];
int weechat_color, fg, bg;
char str_fg[3], str_bg[3], str_pair[6], *error;
int weechat_color, fg, bg, pair;
while (string[0])
{
@@ -245,6 +245,26 @@ gui_chat_string_next_char (struct t_gui_window *window,
string += 6;
}
break;
case GUI_COLOR_PAIR_CHAR: /* pair number */
if ((isdigit (string[1])) && (isdigit (string[2]))
&& (isdigit (string[3])) && (isdigit (string[4]))
&& (isdigit (string[5])))
{
if (apply_style)
{
memcpy (str_pair, string + 1, 5);
str_pair[5] = '\0';
error = NULL;
pair = (int)strtol (str_pair, &error, 10);
if (error && !error[0])
{
gui_window_set_custom_color_pair (GUI_WINDOW_OBJECTS(window)->win_chat,
pair);
}
}
string += 6;
}
break;
case GUI_COLOR_BAR_CHAR: /* bar color */
switch (string[1])
{
+44 -14
View File
@@ -89,18 +89,24 @@ gui_color_search (const char *color_name)
int
gui_color_assign (int *color, const char *color_name)
{
int i;
int color_index, pair;
char *error;
/* look for curses colors in table */
i = 0;
while (gui_weechat_colors[i].string)
error = NULL;
pair = (int)strtol (color_name, &error, 10);
if (error && !error[0] && (pair >= 0))
{
if (string_strcasecmp (gui_weechat_colors[i].string, color_name) == 0)
*color = 0x10000 | pair;
return 1;
}
else
{
color_index = gui_color_search (color_name);
if (color_index >= 0)
{
*color = i;
*color = color_index;
return 1;
}
i++;
}
/* color not found */
@@ -124,13 +130,26 @@ gui_color_get_number ()
const char *
gui_color_get_name (int num_color)
{
static char color[32][16];
static int index_color = 0;
if (num_color & 0x10000)
{
index_color = (index_color + 1) % 32;
color[index_color][0] = '\0';
snprintf (color[index_color], sizeof (color[index_color]),
"%d", num_color & 0xFFFF);
return color[index_color];
}
return gui_weechat_colors[num_color].string;
}
/*
* gui_color_build: build a WeeChat color with foreground,
* background and attributes (attributes are
* given with foreground color, with a OR)
* gui_color_build: build a WeeChat color with foreground and background
* (foreground and background must be >= 0,
* if they are >= 0x10000, then it is a pair number
* (pair = value & 0xFFFF))
*/
void
@@ -144,9 +163,20 @@ gui_color_build (int number, int foreground, int background)
gui_color[number]->string = malloc (4);
}
gui_color[number]->foreground = gui_weechat_colors[foreground].foreground;
gui_color[number]->background = gui_weechat_colors[background].foreground;
gui_color[number]->attributes = gui_weechat_colors[foreground].attributes;
if (foreground & 0x10000)
{
gui_color[number]->foreground = foreground;
gui_color[number]->background = 0;
gui_color[number]->attributes = 0;
}
else
{
if (background & 0x10000)
background = 0;
gui_color[number]->foreground = gui_weechat_colors[foreground].foreground;
gui_color[number]->background = gui_weechat_colors[background].foreground;
gui_color[number]->attributes = gui_weechat_colors[foreground].attributes;
}
if (gui_color[number]->string)
{
snprintf (gui_color[number]->string, 4,
@@ -199,7 +229,7 @@ gui_color_init_pairs ()
* urxvt | xterm-256color | 256 | 32767
* screen | screen | 8 | 64
* screen | screen-256color | 256 | 32767
*/
*/
if (has_colors ())
{
+26 -3
View File
@@ -296,9 +296,17 @@ gui_window_set_weechat_color (WINDOW *window, int num_color)
{
gui_window_reset_style (window, num_color);
wattron (window, gui_color[num_color]->attributes);
gui_window_set_color (window,
gui_color[num_color]->foreground,
gui_color[num_color]->background);
if ((gui_color[num_color]->foreground > 0)
&& (gui_color[num_color]->foreground & 0x10000))
{
wattron (window, COLOR_PAIR(gui_color[num_color]->foreground & 0xFFFF));
}
else
{
gui_window_set_color (window,
gui_color[num_color]->foreground,
gui_color[num_color]->background);
}
}
}
@@ -322,6 +330,21 @@ gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg)
}
}
/*
* 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));
}
}
/*
* gui_window_set_custom_color_fg: set a custom color for a window
* (foreground only)
+1
View File
@@ -86,6 +86,7 @@ extern void gui_window_remove_color_style (WINDOW *window, int style);
extern void gui_window_set_color (WINDOW *window, int fg, int bg);
extern void gui_window_set_weechat_color (WINDOW *window, int num_color);
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);
+67 -42
View File
@@ -88,13 +88,13 @@ gui_color_search_config (const char *color_name)
const char *
gui_color_get_custom (const char *color_name)
{
int fg, bg;
static char color[20][16];
int fg, bg, pair;
static char color[32][16];
static int index_color = 0;
char *pos_comma, *str_fg, *pos_bg;
char *pos_comma, *str_fg, *pos_bg, *error;
/* attribute or other color name (GUI dependent) */
index_color = (index_color + 1) % 20;
index_color = (index_color + 1) % 32;
color[index_color][0] = '\0';
if (!color_name || !color_name[0])
@@ -189,55 +189,74 @@ gui_color_get_custom (const char *color_name)
else
{
/* custom color name (GUI dependent) */
pos_comma = strchr (color_name, ',');
if (pos_comma)
error = NULL;
pair = (int)strtol (color_name, &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;
snprintf (color[index_color], sizeof (color[index_color]),
"%s%s%05d",
GUI_COLOR_COLOR_STR,
GUI_COLOR_PAIR_STR,
pair);
}
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))
pos_comma = strchr (color_name, ',');
if (pos_comma)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%s*%02d,%02d",
GUI_COLOR_COLOR_STR, fg, bg);
if (pos_comma == color_name)
str_fg = NULL;
else
str_fg = string_strndup (color_name, pos_comma - color_name);
pos_bg = pos_comma + 1;
}
}
else if (str_fg && !pos_bg)
{
fg = gui_color_search (str_fg);
if (fg >= 0)
else
{
snprintf (color[index_color], sizeof (color[index_color]),
"%sF%02d",
GUI_COLOR_COLOR_STR, fg);
str_fg = strdup (color_name);
pos_bg = NULL;
}
}
else if (!str_fg && pos_bg)
{
bg = gui_color_search (pos_bg);
if (bg >= 0)
if (str_fg && pos_bg)
{
snprintf (color[index_color], sizeof (color[index_color]),
"%sB%02d",
GUI_COLOR_COLOR_STR, 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 (str_fg)
free (str_fg);
}
return color[index_color];
@@ -288,6 +307,12 @@ gui_color_decode (const char *string, const char *replacement)
&& ptr_string[4] && ptr_string[5])
ptr_string += 6;
break;
case GUI_COLOR_PAIR_CHAR:
if ((isdigit (string[1])) && (isdigit (string[2]))
&& (isdigit (string[3])) && (isdigit (string[4]))
&& (isdigit (string[5])))
ptr_string += 6;
break;
case GUI_COLOR_BAR_CHAR:
ptr_string++;
switch (ptr_string[0])
+2
View File
@@ -97,6 +97,8 @@ enum t_gui_color_enum
#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 "@"
#define GUI_COLOR_BAR_CHAR 'b'
#define GUI_COLOR_BAR_STR "b"
#define GUI_COLOR_BAR_FG_CHAR 'F'