[Aptitude-svn-commit] r3394 - in branches/aptitude-0.3/aptitude: . src/vscreen src/vscreen/config

Daniel Burrows dburrows@costa.debian.org
Wed, 08 Jun 2005 22:50:57 +0000


Author: dburrows
Date: Wed Jun  8 22:50:55 2005
New Revision: 3394

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/config/colors.cc
   branches/aptitude-0.3/aptitude/src/vscreen/config/colors.h
   branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc
Log:
Don't initialize the colors every time that a color-handling routine is
called; this makes it safe to use the text-formatting routines even if
Curses hasn't been initialized.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Jun  8 22:50:55 2005
@@ -1,5 +1,12 @@
 2005-06-08  Daniel Burrows  <dburrows@debian.org>
 
+	* src/vscreen/config/colors.cc, src/vscreen/config/colors.h, src/vscreen/curses++.cc:
+
+	Call init_colors() from init_curses(), and don't call it from the
+	color-handling routines.  This makes it safe to perform 'dummy'
+	color mixing when Curses isn't initialized (for instance, when
+	formatting text from the command-line).
+
 	* src/cmdline/cmdline_show.cc, src/solution_fragment.cc:
 
 	Fix several places where aptitude could crash because I forgot

Modified: branches/aptitude-0.3/aptitude/src/vscreen/config/colors.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/config/colors.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/colors.cc	Wed Jun  8 22:50:55 2005
@@ -21,18 +21,12 @@
 
 #include "../curses++.h"
 
-static bool colors_initted=false;
 static bool colors_avail=false;
 
 // Simplistic allocation scheme for colors: (fg,bg) => fg*COLORS+bg
 
-static void init_colors()
+void init_colors()
 {
-  if(colors_initted)
-    return;
-
-  colors_initted=true;
-
   if(COLOR_PAIRS<COLORS*COLORS || use_default_colors() == ERR)
     return;
 
@@ -50,8 +44,6 @@
 
 int get_color_pair(short fg, short bg)
 {
-  init_colors();
-
   if(!colors_avail)
     return 0;
   else
@@ -64,8 +56,6 @@
 
 int mix_color(short color, short fg, short bg)
 {
-  init_colors();
-
   if(!colors_avail)
     return 0;
   else if(fg == -1 && bg == -1)

Modified: branches/aptitude-0.3/aptitude/src/vscreen/config/colors.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/config/colors.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/colors.h	Wed Jun  8 22:50:55 2005
@@ -27,6 +27,11 @@
 #ifndef COLORS_H
 #define COLORS_H
 
+/** Set up the colors as we expect them to be.  Call this once
+ *  when the program starts.
+ */
+void init_colors();
+
 /** \return a color pair for the given foreground and background. */
 int get_color_pair(short fg, short bg);
 

Modified: branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc	Wed Jun  8 22:50:55 2005
@@ -136,6 +136,7 @@
   keypad(stdscr,TRUE);
 
   start_color();
+  init_colors();
 }
 
 void resize()