diff console/libgnt/gntcolors.c @ 14301:9df5dd999402

[gaim-migrate @ 16991] The color configurations should work now. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 23 Aug 2006 02:34:40 +0000
parents ea5193c23171
children a8632e4bd849
line wrap: on
line diff
--- a/console/libgnt/gntcolors.c	Wed Aug 23 02:21:00 2006 +0000
+++ b/console/libgnt/gntcolors.c	Wed Aug 23 02:34:40 2006 +0000
@@ -23,6 +23,12 @@
 	}
 }
 
+static gboolean
+can_use_custom_color()
+{
+	return (gnt_style_get_bool(GNT_STYLE_COLOR, FALSE) && can_change_color());
+}
+
 static void
 restore_colors()
 {
@@ -36,8 +42,16 @@
 
 void gnt_init_colors()
 {
+	static gboolean init = FALSE;
+
+	if (init)
+		return;
+	init = TRUE;
+
 	start_color();
-	if (gnt_style_get_bool(GNT_STYLE_COLOR, FALSE) && can_change_color())
+	use_default_colors();
+
+	if (can_use_custom_color())
 	{
 		backup_colors();
 
@@ -64,7 +78,6 @@
 	}
 	else
 	{
-		use_default_colors();
 		init_pair(GNT_COLOR_NORMAL, COLOR_BLACK, COLOR_WHITE);
 		init_pair(GNT_COLOR_HIGHLIGHT, COLOR_WHITE, COLOR_BLUE);
 		init_pair(GNT_COLOR_SHADOW, COLOR_BLACK, COLOR_BLACK);
@@ -79,7 +92,7 @@
 void
 gnt_uninit_colors()
 {
-	if (gnt_style_get_bool(GNT_STYLE_COLOR, FALSE) && can_change_color())
+	if (can_use_custom_color())
 		restore_colors();
 }
 
@@ -87,23 +100,28 @@
 get_color(char *key)
 {
 	int color;
+	gboolean custom = can_use_custom_color();
 
 	key = g_strstrip(key);
 
 	if (strcmp(key, "black") == 0)
-		color = GNT_COLOR_BLACK;
+		color = custom ? GNT_COLOR_BLACK : COLOR_BLACK;
 	else if (strcmp(key, "red") == 0)
-		color = GNT_COLOR_RED;
+		color = custom ? GNT_COLOR_RED : COLOR_RED;
 	else if (strcmp(key, "green") == 0)
-		color = GNT_COLOR_GREEN;
+		color = custom ? GNT_COLOR_GREEN : COLOR_GREEN;
 	else if (strcmp(key, "blue") == 0)
-		color = GNT_COLOR_BLUE;
+		color = custom ? GNT_COLOR_BLUE : COLOR_BLUE;
 	else if (strcmp(key, "white") == 0)
-		color = GNT_COLOR_WHITE;
+		color = custom ? GNT_COLOR_WHITE : COLOR_WHITE;
 	else if (strcmp(key, "gray") == 0)
-		color = GNT_COLOR_GRAY;
+		color = custom ? GNT_COLOR_GRAY : COLOR_YELLOW;  /* eh? */
 	else if (strcmp(key, "darkgray") == 0)
-		color = GNT_COLOR_DARK_GRAY;
+		color = custom ? GNT_COLOR_DARK_GRAY : COLOR_BLACK;
+	else if (strcmp(key, "magenta") == 0)
+		color = COLOR_MAGENTA;
+	else if (strcmp(key, "cyan") == 0)
+		color = COLOR_CYAN;
 	else
 		color = -1;
 	return color;
@@ -122,8 +140,9 @@
 		g_error_free(error);
 		error = NULL;
 	}
-	else
+	else if (nkeys)
 	{
+		gnt_init_colors();
 		while (nkeys--)
 		{
 			gsize len;
@@ -164,6 +183,8 @@
 		g_error_free(error);
 		return;
 	}
+	else if (nkeys)
+		gnt_init_colors();
 
 	while (nkeys--)
 	{