changeset 13851:41753203a94d

[gaim-migrate @ 16310] The colors should now look 'better' in terminals that don't apparently allow changing colors. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 22 Jun 2006 22:38:03 +0000
parents 0e1e59770cb0
children d95e5e0e29b9
files console/libgnt/gntcolors.c console/libgnt/gnttree.c console/libgnt/test.c
diffstat 3 files changed, 46 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gntcolors.c	Thu Jun 22 08:33:54 2006 +0000
+++ b/console/libgnt/gntcolors.c	Thu Jun 22 22:38:03 2006 +0000
@@ -3,19 +3,29 @@
 
 void gnt_init_colors()
 {
-	/* XXX: 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, 0, 0, 1000);
-	init_color(GNT_COLOR_WHITE, 1000, 1000, 1000);
-	init_color(GNT_COLOR_GRAY, 799, 799, 799);
-	init_color(GNT_COLOR_DARK_GRAY, 256, 256, 256);
+	if (can_change_color())
+	{
+		/* XXX: 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, 0, 0, 1000);
+		init_color(GNT_COLOR_WHITE, 1000, 1000, 1000);
+		init_color(GNT_COLOR_GRAY, 799, 799, 799);
+		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_BLUE, GNT_COLOR_GRAY);
-	init_pair(GNT_COLOR_SHADOW, GNT_COLOR_BLACK, GNT_COLOR_DARK_GRAY);
-	init_pair(GNT_COLOR_TITLE, GNT_COLOR_WHITE, GNT_COLOR_DARK_GRAY);
+		/* Now some init_pair()s */
+		init_pair(GNT_COLOR_NORMAL, GNT_COLOR_BLACK, GNT_COLOR_WHITE);
+		init_pair(GNT_COLOR_HIGHLIGHT, GNT_COLOR_BLUE, GNT_COLOR_GRAY);
+		init_pair(GNT_COLOR_SHADOW, GNT_COLOR_BLACK, GNT_COLOR_DARK_GRAY);
+		init_pair(GNT_COLOR_TITLE, GNT_COLOR_WHITE, GNT_COLOR_DARK_GRAY);
+	}
+	else
+	{
+		init_pair(GNT_COLOR_NORMAL, COLOR_BLACK, COLOR_WHITE);
+		init_pair(GNT_COLOR_HIGHLIGHT, COLOR_CYAN, COLOR_BLACK);
+		init_pair(GNT_COLOR_SHADOW, COLOR_BLACK, COLOR_BLACK);
+		init_pair(GNT_COLOR_TITLE, COLOR_WHITE, COLOR_BLACK);
+	}
 }
 
--- a/console/libgnt/gnttree.c	Thu Jun 22 08:33:54 2006 +0000
+++ b/console/libgnt/gnttree.c	Thu Jun 22 22:38:03 2006 +0000
@@ -47,14 +47,17 @@
 
 	wbkgd(tree->scroll, COLOR_PAIR(GNT_COLOR_NORMAL));
 
-	/* XXX: Add the rows */
 	for (start = tree->top, iter = g_list_nth(tree->list, tree->top);
 				iter && start < tree->bottom; start++, iter = iter->next)
 	{
 		char str[2096];	/* XXX: This should be safe for any terminal */
 		GntTreeRow *row = g_hash_table_lookup(tree->hash, iter->data);
 
-		snprintf(str, widget->priv.width - 2, "%s\n", row->text);
+		if (snprintf(str, widget->priv.width, "%s\n", row->text) >= widget->priv.width)
+		{
+			/* XXX: ellipsize */
+			str[widget->priv.width - 1] = 0;
+		}
 		
 		if (start == tree->current)
 		{
@@ -83,7 +86,7 @@
 
 	/* For the Tree (or anything that scrolls), we will create a 'hidden' window
 	 * of 'large enough' size. We never wrefresh that hidden-window, instead we
-	 * just 'scroll' it, and wrefresh the subwindow */
+	 * just copy stuff from it into the visible window */
 
 	if (tree->scroll == NULL)
 	{
--- a/console/libgnt/test.c	Thu Jun 22 08:33:54 2006 +0000
+++ b/console/libgnt/test.c	Thu Jun 22 22:38:03 2006 +0000
@@ -2,11 +2,21 @@
 #include "gnt.h"
 #include "gntkeys.h"
 #include "gnttree.h"
+#include "gntbox.h"
 
 static gboolean
 key_pressed(GntWidget *widget, const char *text, gpointer null)
 {
 	GntWidget *w = null;
+	GntWidget *box = gnt_box_new(FALSE, FALSE);
+	GntWidget *label = gnt_label_new("so wassup!!");
+
+	gnt_box_add_widget(GNT_BOX(box), label);
+	GNT_WIDGET_UNSET_FLAGS(box, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
+	gnt_box_set_title(GNT_BOX(box), "This is a test");
+
+	gnt_widget_show(box);
+#if 0
 
 	gnt_widget_set_focus(w, TRUE);
 
@@ -24,6 +34,7 @@
 	}
 
 	gnt_widget_draw(w);
+#endif
 
 	return FALSE;
 }
@@ -75,14 +86,14 @@
 	gnt_widget_set_name(widget, "widget");
 	gnt_widget_set_name(widget2, "widget2");
 
-	gnt_box_add_widget(vbox, widget);
-	gnt_box_add_widget(vbox, widget2);
+	gnt_box_add_widget(GNT_BOX(vbox), widget);
+	gnt_box_add_widget(GNT_BOX(vbox), widget2);
 
-	gnt_box_add_widget(hbox, label);
-	gnt_box_add_widget(hbox, vbox);
+	gnt_box_add_widget(GNT_BOX(hbox), label);
+	gnt_box_add_widget(GNT_BOX(hbox), vbox);
 
 	tree = gnt_tree_new();
-	gnt_box_add_widget(hbox, tree);
+	gnt_box_add_widget(GNT_BOX(hbox), tree);
 
 	gnt_tree_add_row_after(GNT_TREE(tree), "a", "a", NULL, NULL);
 	gnt_tree_add_row_after(GNT_TREE(tree), "c", "c", NULL, NULL);
@@ -91,7 +102,7 @@
 	gnt_tree_add_row_after(GNT_TREE(tree), "b", "b", "d", NULL);
 
 	GNT_WIDGET_UNSET_FLAGS(hbox, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW);
-	gnt_box_set_title(hbox, "111111111111111111111111111111111111111111111111111111111111111This is the title …");
+	gnt_box_set_title(GNT_BOX(hbox), "111111111111111111111111111111111111111111111111111111111111111This is the title …");
 
 	/*gnt_widget_set_take_focus(vbox, TRUE);*/
 	/*gnt_widget_set_take_focus(hbox, TRUE);*/