int gui_color_assign (int *color, const char *color_name) { int flag, extra_attr, color_index, number; char *error; /* read extended attributes */ extra_attr = 0; while ((flag = gui_color_attr_get_flag (color_name[0])) > 0) { extra_attr |= flag; color_name++; } /* is it a color alias? */ number = gui_color_palette_get_alias (color_name); if (number >= 0) { *color = number | GUI_COLOR_EXTENDED_FLAG | extra_attr; return 1; } /* is it a color number? */ error = NULL; number = (int)strtol (color_name, &error, 10); if (color_name[0] && error && !error[0] && (number >= 0)) { /* color_name is a number, use this color number */ if (number > GUI_COLOR_EXTENDED_MAX) number = GUI_COLOR_EXTENDED_MAX; *color = number | GUI_COLOR_EXTENDED_FLAG | extra_attr; return 1; } else { /* search for basic WeeChat color */ color_index = gui_color_search (color_name); if (color_index >= 0) { *color = color_index | extra_attr; return 1; } } /* color not found */ return 0; }
const char * gui_color_get_custom (const char *color_name) { int fg, bg, fg_term, bg_term, term_color; static char color[32][32]; static int index_color = 0; char color_fg[32], color_bg[32]; char *pos_delim, *str_fg, *pos_bg, *error, *color_attr; const char *ptr_color_name; /* attribute or other color name (GUI dependent) */ index_color = (index_color + 1) % 32; color[index_color][0] = '\0'; if (!color_name || !color_name[0]) return color[index_color]; if (string_strcasecmp (color_name, "reset") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c", GUI_COLOR_RESET_CHAR); } else if (string_strcasecmp (color_name, "resetcolor") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c", GUI_COLOR_COLOR_CHAR, GUI_COLOR_RESET_CHAR); } else if (string_strcasecmp (color_name, "bold") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c", GUI_COLOR_SET_ATTR_CHAR, GUI_COLOR_ATTR_BOLD_CHAR); } else if (string_strcasecmp (color_name, "-bold") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c", GUI_COLOR_REMOVE_ATTR_CHAR, GUI_COLOR_ATTR_BOLD_CHAR); } else if (string_strcasecmp (color_name, "reverse") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c", GUI_COLOR_SET_ATTR_CHAR, GUI_COLOR_ATTR_REVERSE_CHAR); } else if (string_strcasecmp (color_name, "-reverse") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c", GUI_COLOR_REMOVE_ATTR_CHAR, GUI_COLOR_ATTR_REVERSE_CHAR); } else if (string_strcasecmp (color_name, "italic") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c", GUI_COLOR_SET_ATTR_CHAR, GUI_COLOR_ATTR_ITALIC_CHAR); } else if (string_strcasecmp (color_name, "-italic") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c", GUI_COLOR_REMOVE_ATTR_CHAR, GUI_COLOR_ATTR_ITALIC_CHAR); } else if (string_strcasecmp (color_name, "underline") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c", GUI_COLOR_SET_ATTR_CHAR, GUI_COLOR_ATTR_UNDERLINE_CHAR); } else if (string_strcasecmp (color_name, "-underline") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c", GUI_COLOR_REMOVE_ATTR_CHAR, GUI_COLOR_ATTR_UNDERLINE_CHAR); } else if (string_strcasecmp (color_name, "bar_fg") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c%c", GUI_COLOR_COLOR_CHAR, GUI_COLOR_BAR_CHAR, GUI_COLOR_BAR_FG_CHAR); } else if (string_strcasecmp (color_name, "bar_delim") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c%c", GUI_COLOR_COLOR_CHAR, GUI_COLOR_BAR_CHAR, GUI_COLOR_BAR_DELIM_CHAR); } else if (string_strcasecmp (color_name, "bar_bg") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c%c", GUI_COLOR_COLOR_CHAR, GUI_COLOR_BAR_CHAR, GUI_COLOR_BAR_BG_CHAR); } else { /* custom color name (GUI dependent) */ fg_term = -1; bg_term = -1; fg = -1; bg = -1; color_attr = NULL; color_fg[0] = '\0'; color_bg[0] = '\0'; /* read extra attributes (bold, ..) */ ptr_color_name = color_name; while (gui_color_attr_get_flag (ptr_color_name[0]) > 0) { ptr_color_name++; } if (ptr_color_name != color_name) { color_attr = string_strndup (color_name, ptr_color_name - color_name); } pos_delim = strchr (ptr_color_name, ','); if (!pos_delim) pos_delim = strchr (ptr_color_name, ':'); if (pos_delim) { if (pos_delim == ptr_color_name) str_fg = NULL; else str_fg = string_strndup (ptr_color_name, pos_delim - ptr_color_name); pos_bg = pos_delim + 1; } else { str_fg = strdup (ptr_color_name); pos_bg = NULL; } if (str_fg) { fg_term = gui_color_palette_get_alias (str_fg); if (fg_term < 0) { error = NULL; term_color = (int)strtol (str_fg, &error, 10); if (error && !error[0]) { fg_term = term_color; if (fg_term < 0) fg_term = 0; else if (fg_term > GUI_COLOR_EXTENDED_MAX) fg_term = GUI_COLOR_EXTENDED_MAX; } else fg = gui_color_search (str_fg); } } if (pos_bg) { bg_term = gui_color_palette_get_alias (pos_bg); if (bg_term < 0) { error = NULL; term_color = (int)strtol (pos_bg, &error, 10); if (error && !error[0]) { bg_term = term_color; if (bg_term < 0) bg_term = 0; else if (bg_term > GUI_COLOR_EXTENDED_MAX) bg_term = GUI_COLOR_EXTENDED_MAX; } else bg = gui_color_search (pos_bg); } } if (fg_term >= 0) { snprintf (color_fg, sizeof (color_fg), "%c%s%05d", GUI_COLOR_EXTENDED_CHAR, (color_attr) ? color_attr : "", fg_term); } else if (fg >= 0) { snprintf (color_fg, sizeof (color_fg), "%s%02d", (color_attr) ? color_attr : "", fg); } if (bg_term >= 0) { snprintf (color_bg, sizeof (color_bg), "%c%05d", GUI_COLOR_EXTENDED_CHAR, bg_term); } 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 (color_attr) free (color_attr); if (str_fg) free (str_fg); } return color[index_color]; }
void gui_color_init_weechat () { if (CONFIG_BOOLEAN(config_look_color_basic_force_bold) || (gui_color_term_colors < 16)) { gui_weechat_colors = gui_weechat_colors_bold; } else { gui_weechat_colors = gui_weechat_colors_no_bold; } gui_color_build (GUI_COLOR_SEPARATOR, CONFIG_COLOR(config_color_separator), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT, CONFIG_COLOR(config_color_chat), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_TIME, CONFIG_COLOR(config_color_chat_time), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_TIME_DELIMITERS, CONFIG_COLOR(config_color_chat_time_delimiters), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_PREFIX_ERROR, CONFIG_COLOR(config_color_chat_prefix[GUI_CHAT_PREFIX_ERROR]), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_PREFIX_NETWORK, CONFIG_COLOR(config_color_chat_prefix[GUI_CHAT_PREFIX_NETWORK]), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_PREFIX_ACTION, CONFIG_COLOR(config_color_chat_prefix[GUI_CHAT_PREFIX_ACTION]), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_PREFIX_JOIN, CONFIG_COLOR(config_color_chat_prefix[GUI_CHAT_PREFIX_JOIN]), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_PREFIX_QUIT, CONFIG_COLOR(config_color_chat_prefix[GUI_CHAT_PREFIX_QUIT]), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_PREFIX_MORE, CONFIG_COLOR(config_color_chat_prefix_more), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_PREFIX_SUFFIX, CONFIG_COLOR(config_color_chat_prefix_suffix), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_BUFFER, CONFIG_COLOR(config_color_chat_buffer), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_SERVER, CONFIG_COLOR(config_color_chat_server), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_CHANNEL, CONFIG_COLOR(config_color_chat_channel), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK, CONFIG_COLOR(config_color_chat_nick), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK_SELF, CONFIG_COLOR(config_color_chat_nick_self), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK_OTHER, CONFIG_COLOR(config_color_chat_nick_other), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_HOST, CONFIG_COLOR(config_color_chat_host), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_DELIMITERS, CONFIG_COLOR(config_color_chat_delimiters), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_HIGHLIGHT, CONFIG_COLOR(config_color_chat_highlight), CONFIG_COLOR(config_color_chat_highlight_bg)); gui_color_build (GUI_COLOR_CHAT_READ_MARKER, CONFIG_COLOR(config_color_chat_read_marker), CONFIG_COLOR(config_color_chat_read_marker_bg)); gui_color_build (GUI_COLOR_CHAT_TEXT_FOUND, CONFIG_COLOR(config_color_chat_text_found), CONFIG_COLOR(config_color_chat_text_found_bg)); gui_color_build (GUI_COLOR_CHAT_VALUE, CONFIG_COLOR(config_color_chat_value), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_PREFIX_BUFFER, CONFIG_COLOR(config_color_chat_prefix_buffer), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_TAGS, CONFIG_COLOR(config_color_chat_tags), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_INACTIVE_WINDOW, CONFIG_COLOR(config_color_chat_inactive_window), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_INACTIVE_BUFFER, CONFIG_COLOR(config_color_chat_inactive_buffer), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_PREFIX_BUFFER_INACTIVE_BUFFER, CONFIG_COLOR(config_color_chat_prefix_buffer_inactive_buffer), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK_OFFLINE, CONFIG_COLOR(config_color_chat_nick_offline), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK_OFFLINE_HIGHLIGHT, CONFIG_COLOR(config_color_chat_nick_offline_highlight), CONFIG_COLOR(config_color_chat_nick_offline_highlight_bg)); gui_color_build (GUI_COLOR_CHAT_NICK_PREFIX, CONFIG_COLOR(config_color_chat_nick_prefix), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK_SUFFIX, CONFIG_COLOR(config_color_chat_nick_suffix), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_EMPHASIS, CONFIG_COLOR(config_color_emphasized), CONFIG_COLOR(config_color_emphasized_bg)); gui_color_build (GUI_COLOR_CHAT_DAY_CHANGE, CONFIG_COLOR(config_color_chat_day_change), CONFIG_COLOR(config_color_chat_bg)); /* * define old nick colors for compatibility on /upgrade with previous * versions: these colors have been removed in version 0.3.4 and replaced * by new option "weechat.color.chat_nick_colors", which is a list of * colors (without limit on number of colors) */ gui_color_build (GUI_COLOR_CHAT_NICK1_OBSOLETE, gui_color_search ("cyan"), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK2_OBSOLETE, gui_color_search ("magenta"), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK3_OBSOLETE, gui_color_search ("green"), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK4_OBSOLETE, gui_color_search ("brown"), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK5_OBSOLETE, gui_color_search ("lightblue"), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK6_OBSOLETE, gui_color_search ("default"), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK7_OBSOLETE, gui_color_search ("lightcyan"), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK8_OBSOLETE, gui_color_search ("lightmagenta"), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK9_OBSOLETE, gui_color_search ("lightgreen"), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK10_OBSOLETE, gui_color_search ("blue"), CONFIG_COLOR(config_color_chat_bg)); }
const char * gui_color_get_custom (const char *color_name) { int fg, bg; static char color[20][16]; static int index_color = 0; char *pos_comma, *str_fg, *pos_bg; /* attribute or other color name (GUI dependent) */ index_color = (index_color + 1) % 20; color[index_color][0] = '\0'; if (!color_name || !color_name[0]) return color[index_color]; if (string_strcasecmp (color_name, "reset") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%s", GUI_COLOR_RESET_STR); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } 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); } else if (string_strcasecmp (color_name, "bar_fg") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c%c", GUI_COLOR_COLOR_CHAR, GUI_COLOR_BAR_CHAR, GUI_COLOR_BAR_FG_CHAR); } else if (string_strcasecmp (color_name, "bar_delim") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c%c", GUI_COLOR_COLOR_CHAR, GUI_COLOR_BAR_CHAR, GUI_COLOR_BAR_DELIM_CHAR); } else if (string_strcasecmp (color_name, "bar_bg") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%c%c%c", GUI_COLOR_COLOR_CHAR, GUI_COLOR_BAR_CHAR, GUI_COLOR_BAR_BG_CHAR); } else { /* custom color name (GUI dependent) */ pos_comma = strchr (color_name, ','); if (pos_comma) { 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 { 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); snprintf (color[index_color], sizeof (color[index_color]), "%s*%02d,%02d", GUI_COLOR_COLOR_STR, fg, bg); } else if (str_fg && !pos_bg) { fg = gui_color_search (str_fg); snprintf (color[index_color], sizeof (color[index_color]), "%sF%02d", GUI_COLOR_COLOR_STR, fg); } else if (!str_fg && pos_bg) { bg = gui_color_search (pos_bg); snprintf (color[index_color], sizeof (color[index_color]), "%sB%02d", GUI_COLOR_COLOR_STR, bg); } if (str_fg) free (str_fg); } return color[index_color]; }