Skip to content
Permalink
Browse files

core: add function to convert WeeChat colors to ANSI colors (issue #528)

  • Loading branch information...
flashcode committed Sep 29, 2019
1 parent 177fa6c commit 90f711a965356e315c494acc533b62b80d3d0ead
@@ -115,7 +115,7 @@ int gui_color_timer = 0; /* timer in seconds */
/*
* Searches for a color by name.
*
* Return index of color in WeeChat colors table, -1 if not found.
* Returns index of color in WeeChat colors table, -1 if not found.
*/

int
@@ -133,12 +133,33 @@ gui_color_search (const char *color_name)
return -1;
}

/*
* Searches for a color by index.
*
* Returns name of color in WeeChat colors table, NULL if not found.
*/

const char *
gui_color_search_index (int index)
{
int i;

for (i = 0; gui_weechat_colors[i].string; i++)
{
if (i == index)
return gui_weechat_colors[i].string;
}

/* color not found */
return NULL;
}

/*
* Get Curses attributes corresponding to extended attributes flags in a color.
*/

int
gui_color_get_extended_attrs (int color)
gui_color_get_gui_attrs (int color)
{
int attributes;

@@ -156,6 +177,29 @@ gui_color_get_extended_attrs (int color)
return attributes;
}

/*
* Get extended flags corresponding to Curses attributes in a color.
*/

int
gui_color_get_extended_flags (int attrs)
{
int flags;

flags = 0;

if (attrs & A_BOLD)
flags |= GUI_COLOR_EXTENDED_BOLD_FLAG;
if (attrs & A_REVERSE)
flags |= GUI_COLOR_EXTENDED_REVERSE_FLAG;
if (attrs & A_ITALIC)
flags |= GUI_COLOR_EXTENDED_ITALIC_FLAG;
if (attrs & A_UNDERLINE)
flags |= GUI_COLOR_EXTENDED_UNDERLINE_FLAG;

return flags;
}

/*
* Assigns a WeeChat color (read from configuration).
*
@@ -546,7 +590,7 @@ gui_color_build (int number, int foreground, int background)
gui_color[number]->foreground = gui_weechat_colors[foreground & GUI_COLOR_EXTENDED_MASK].foreground;
gui_color[number]->attributes = gui_weechat_colors[foreground & GUI_COLOR_EXTENDED_MASK].attributes;
}
gui_color[number]->attributes |= gui_color_get_extended_attrs (foreground);
gui_color[number]->attributes |= gui_color_get_gui_attrs (foreground);

/* set background */
if (background & GUI_COLOR_EXTENDED_FLAG)
@@ -181,7 +181,7 @@ gui_window_clear (WINDOW *window, int fg, int bg)
if (!gui_init_ok)
return;

attrs = gui_color_get_extended_attrs (fg);
attrs = gui_color_get_gui_attrs (fg);

if ((fg > 0) && (fg & GUI_COLOR_EXTENDED_FLAG))
fg &= GUI_COLOR_EXTENDED_MASK;
@@ -420,7 +420,7 @@ gui_window_set_custom_color_fg (WINDOW *window, int fg)
{
if (!(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
gui_window_remove_color_style (window, A_ALL_ATTR);
attributes = gui_color_get_extended_attrs (fg) |
attributes = gui_color_get_gui_attrs (fg) |
gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].attributes;
gui_window_set_color_style (window, attributes);
fg = gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].foreground;
@@ -505,7 +505,7 @@ gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg,
{
if (reset_attributes && !(fg & GUI_COLOR_EXTENDED_KEEPATTR_FLAG))
gui_window_remove_color_style (window, A_ALL_ATTR);
attributes = gui_color_get_extended_attrs (fg) |
attributes = gui_color_get_gui_attrs (fg) |
gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].attributes;
gui_window_set_color_style (window, attributes);
fg = gui_weechat_colors[fg & GUI_COLOR_EXTENDED_MASK].foreground;
@@ -91,7 +91,8 @@ extern void gui_main_init ();
extern void gui_main_loop ();

/* color functions */
extern int gui_color_get_extended_attrs (int color);
extern int gui_color_get_gui_attrs (int color);
extern int gui_color_get_extended_flags (int attrs);
extern int gui_color_get_pair (int fg, int bg);
extern int gui_color_weechat_get_pair (int weechat_color);
extern void gui_color_alloc ();
@@ -45,10 +45,10 @@
#define COLOR_WHITE 7

#define A_NORMAL 0
#define A_BOLD 0
#define A_UNDERLINE 0
#define A_REVERSE 0
#define A_ITALIC 0
#define A_BOLD (1 << (13 + 8))
#define A_UNDERLINE (1 << (9 + 8))
#define A_REVERSE (1 << (10 + 8))
#define A_ITALIC (1 << (23 + 8))

#define ACS_HLINE '-'
#define ACS_VLINE '|'

0 comments on commit 90f711a

Please sign in to comment.
You can’t perform that action at this time.