summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-12-17 09:54:46 +0100
committerSebastien Helleu <flashcode@flashtux.org>2010-12-17 09:54:46 +0100
commit4043ca3d38df247850e3f95fa5b8c3a14140c23e (patch)
treea7e8b009f26a0f6040094e1ae4990161ab10a59f /src/gui
parentf2c9961a21ad56cc5f6440e2dd661a588188c149 (diff)
downloadweechat-4043ca3d38df247850e3f95fa5b8c3a14140c23e.zip
Allow use of color pair number in color options and in API function "weechat_color"
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-bar-window.c21
-rw-r--r--src/gui/curses/gui-curses-chat.c24
-rw-r--r--src/gui/curses/gui-curses-color.c58
-rw-r--r--src/gui/curses/gui-curses-window.c29
-rw-r--r--src/gui/curses/gui-curses.h1
-rw-r--r--src/gui/gui-color.c109
-rw-r--r--src/gui/gui-color.h2
7 files changed, 182 insertions, 62 deletions
diff --git a/src/gui/curses/gui-curses-bar-window.c b/src/gui/curses/gui-curses-bar-window.c
index 6130ccb04..fe1c617b9 100644
--- a/src/gui/curses/gui-curses-bar-window.c
+++ b/src/gui/curses/gui-curses-bar-window.c
@@ -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])
{
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 3653c1d78..4a655e493 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -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])
{
diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c
index 9638841c6..9d8a484a6 100644
--- a/src/gui/curses/gui-curses-color.c
+++ b/src/gui/curses/gui-curses-color.c
@@ -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 ())
{
diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c
index 7e215a5b7..5b4848a4d 100644
--- a/src/gui/curses/gui-curses-window.c
+++ b/src/gui/curses/gui-curses-window.c
@@ -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);
+ }
}
}
@@ -323,6 +331,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)
*/
diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h
index 133d4fa02..cd4087593 100644
--- a/src/gui/curses/gui-curses.h
+++ b/src/gui/curses/gui-curses.h
@@ -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);
diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c
index 99c8bc065..326e3f542 100644
--- a/src/gui/gui-color.c
+++ b/src/gui/gui-color.c
@@ -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])
diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h
index 0d8872b19..0bbbda209 100644
--- a/src/gui/gui-color.h
+++ b/src/gui/gui-color.h
@@ -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'