* GNT - The GLib Ncurses Toolkit * GNT is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA #define GNT_LOG_DOMAIN "Colors" static gboolean hascolors; static int custom_type = GNT_COLORS; } colors[GNT_TOTAL_COLORS]; for (i = 0; i < GNT_TOTAL_COLORS; i++) color_content(i, &colors[i].r, &colors[i].g, &colors[i].b); can_use_custom_color(void) return (gnt_style_get_bool(GNT_STYLE_COLOR, FALSE) && can_change_color()); for (i = 0; i < GNT_TOTAL_COLORS; i++) init_color(i, colors[i].r, colors[i].g, colors[i].b); static gboolean init = FALSE; if (!(hascolors = has_colors())) defaults = use_default_colors(); if (can_use_custom_color()) /* Do some init_color()s */ init_color(GNT_COLOR_BLACK, 0, 0, 0); init_color(GNT_COLOR_RED, 1000, 0, 0); init_color(GNT_COLOR_GREEN, 0, 1000, 0); init_color(GNT_COLOR_BLUE, 250, 250, 700); init_color(GNT_COLOR_WHITE, 1000, 1000, 1000); init_color(GNT_COLOR_GRAY, 699, 699, 699); init_color(GNT_COLOR_DARK_GRAY, 256, 256, 256); /* Now some init_pair()s */ init_pair(GNT_COLOR_NORMAL, GNT_COLOR_BLACK, GNT_COLOR_WHITE); init_pair(GNT_COLOR_HIGHLIGHT, GNT_COLOR_WHITE, GNT_COLOR_BLUE); init_pair(GNT_COLOR_SHADOW, GNT_COLOR_BLACK, GNT_COLOR_DARK_GRAY); init_pair(GNT_COLOR_TITLE, GNT_COLOR_WHITE, GNT_COLOR_BLUE); init_pair(GNT_COLOR_TITLE_D, GNT_COLOR_WHITE, GNT_COLOR_GRAY); init_pair(GNT_COLOR_TEXT_NORMAL, GNT_COLOR_WHITE, GNT_COLOR_BLUE); init_pair(GNT_COLOR_HIGHLIGHT_D, GNT_COLOR_BLACK, GNT_COLOR_GRAY); init_pair(GNT_COLOR_DISABLED, GNT_COLOR_GRAY, GNT_COLOR_WHITE); init_pair(GNT_COLOR_URGENT, GNT_COLOR_WHITE, GNT_COLOR_RED); init_pair(GNT_COLOR_NORMAL, -1, -1); init_pair(GNT_COLOR_NORMAL, COLOR_BLACK, COLOR_WHITE); init_pair(GNT_COLOR_DISABLED, COLOR_YELLOW, bg); init_pair(GNT_COLOR_URGENT, COLOR_GREEN, bg); init_pair(GNT_COLOR_HIGHLIGHT, COLOR_WHITE, COLOR_BLUE); init_pair(GNT_COLOR_SHADOW, COLOR_BLACK, COLOR_BLACK); init_pair(GNT_COLOR_TITLE, COLOR_WHITE, COLOR_BLUE); init_pair(GNT_COLOR_TITLE_D, COLOR_WHITE, COLOR_BLACK); init_pair(GNT_COLOR_TEXT_NORMAL, COLOR_WHITE, COLOR_BLUE); init_pair(GNT_COLOR_HIGHLIGHT_D, COLOR_CYAN, COLOR_BLACK); if (can_use_custom_color()) gnt_colors_get_color(char *key) gboolean custom = can_use_custom_color(); if (strcmp(key, "black") == 0) color = custom ? GNT_COLOR_BLACK : COLOR_BLACK; else if (strcmp(key, "red") == 0) color = custom ? GNT_COLOR_RED : COLOR_RED; else if (strcmp(key, "green") == 0) color = custom ? GNT_COLOR_GREEN : COLOR_GREEN; else if (strcmp(key, "blue") == 0) color = custom ? GNT_COLOR_BLUE : COLOR_BLUE; else if (strcmp(key, "white") == 0) color = custom ? GNT_COLOR_WHITE : COLOR_WHITE; else if (strcmp(key, "gray") == 0 || strcmp(key, "grey") == 0) color = custom ? GNT_COLOR_GRAY : COLOR_YELLOW; /* eh? */ else if (strcmp(key, "darkgray") == 0 || strcmp(key, "darkgrey") == 0) color = custom ? GNT_COLOR_DARK_GRAY : COLOR_BLACK; else if (strcmp(key, "magenta") == 0) else if (strcmp(key, "cyan") == 0) else if (strcmp(key, "default") == 0) g_warning("Invalid color name: %s\n", key); void gnt_colors_parse(GKeyFile *kfile) if (!g_key_file_has_group(kfile, "colors")) { gnt_color_pairs_parse(kfile); keys = g_key_file_get_keys(kfile, "colors", &nkeys, &error); gnt_warning("%s", error->message); gchar *key = keys[nkeys]; char **list = g_key_file_get_string_list(kfile, "colors", key, &len, NULL); key = g_ascii_strdown(key, -1); color = gnt_colors_get_color(key); init_color(color, r, g, b); gnt_color_pairs_parse(kfile); void gnt_color_pairs_parse(GKeyFile *kfile) if (!g_key_file_has_group(kfile, "colorpairs")) keys = g_key_file_get_keys(kfile, "colorpairs", &nkeys, &error); gnt_warning("%s", error->message); gchar *key = keys[nkeys]; char **list = g_key_file_get_string_list(kfile, "colorpairs", key, &len, NULL); gchar *fgc = g_ascii_strdown(list[0], -1); gchar *bgc = g_ascii_strdown(list[1], -1); int fg = gnt_colors_get_color(fgc); int bg = gnt_colors_get_color(bgc); if (fg == -EINVAL || bg == -EINVAL) { key = g_ascii_strdown(key, -1); if (strcmp(key, "normal") == 0) else if (strcmp(key, "highlight") == 0) type = GNT_COLOR_HIGHLIGHT; else if (strcmp(key, "highlightd") == 0) type = GNT_COLOR_HIGHLIGHT_D; else if (strcmp(key, "shadow") == 0) else if (strcmp(key, "title") == 0) else if (strcmp(key, "titled") == 0) type = GNT_COLOR_TITLE_D; else if (strcmp(key, "text") == 0) type = GNT_COLOR_TEXT_NORMAL; else if (strcmp(key, "disabled") == 0) type = GNT_COLOR_DISABLED; else if (strcmp(key, "urgent") == 0) int gnt_color_pair(int pair) return (hascolors ? COLOR_PAIR(pair) : ((pair == GNT_COLOR_NORMAL || pair == GNT_COLOR_HIGHLIGHT_D || pair == GNT_COLOR_TITLE_D || pair == GNT_COLOR_DISABLED) ? 0 : (int)A_STANDOUT)); int gnt_color_add_pair(int fg, int bg) init_pair(custom_type, fg, bg);