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

Daniel Burrows dburrows at costa.debian.org
Sun Sep 25 18:18:27 UTC 2005


Author: dburrows
Date: Sun Sep 25 18:18:23 2005
New Revision: 4259

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/load_config.cc
   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/config/style.h
Log:
Add support for the default background; currently the default
foreground is NOT supported (there aren't enough colors available).

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Sun Sep 25 18:18:23 2005
@@ -1,5 +1,17 @@
 2005-09-25  Daniel Burrows  <dburrows at debian.org>
 
+	* src/load_config.cc, src/vscreen/config/colors.cc, src/vscreen/config/colors.h, src/vscreen/config/style.cc, src/vscreen/config/style.h:
+
+	  Support using the default background color by encoding it in the
+	  slots that would be used for an identical foreground &
+	  background color.  Attempts to set identical foreground &
+	  background now return an arbitrary color with the same
+	  background, and the style code sets A_INVIS in such a case
+	  (resulting in a blank space with the same background).  This is
+	  a bit of a hack, but it's the only way to do this when you
+	  consider that xterm provides 9 colors (including the default
+	  color) but only 64 color pairs.  (Closes: #161872)
+
 	* src/cmdline/cmdline_clean.cc:
 
 	  Unreverse the logic that determines the return value of 'clean':

Modified: branches/aptitude-0.3/aptitude/src/load_config.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/load_config.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/load_config.cc	Sun Sep 25 18:18:23 2005
@@ -39,6 +39,8 @@
     return COLOR_CYAN;
   else if(!strcasecmp(cs, "white"))
     return COLOR_WHITE;
+  else if(!strcasecmp(cs, "default"))
+    return -1;
   else
     {
       _error->Error(_("Unrecognized color name \"%s\""), cs);
@@ -116,7 +118,14 @@
 	  for(Configuration::Item const *j=i->Child; j; j=j->Next)
 	    {
 	      if(!strcasecmp(j->Tag.c_str(), "fg"))
-		curr.set_fg(parse_color(j->Value));
+		{
+		  int c = parse_color(j->Value);
+
+		  if(c == -1)
+		    _error->Error(_("The default color may only be used as a background."));
+		  else
+		    curr.set_fg(c);
+		}
 	      else if(!strcasecmp(j->Tag.c_str(), "bg"))
 		curr.set_bg(parse_color(j->Value));
 	      else

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	Sun Sep 25 18:18:23 2005
@@ -22,6 +22,7 @@
 #include <vscreen/curses++.h>
 
 static bool colors_avail=false;
+static bool default_colors_avail = false;
 
 // Simplistic allocation scheme for colors: (fg,bg) => fg*COLORS+bg
 
@@ -35,7 +36,9 @@
   for(short fg=0; fg<COLORS; ++fg)
     for(short bg=0; bg<COLORS; ++bg)
       {
-	if(fg==0 && bg==0)
+	if(default_colors_avail && fg == bg)
+	  init_pair(fg * COLORS + bg, fg, -1);
+	else if(fg == 0 && bg == 0)
 	  // do nothing; on some terminals, doing this causes the
 	  // cursor to become INVISIBLE, and black-on-black text is a
 	  // bad idea anyway..
@@ -52,9 +55,21 @@
     return 0;
   else
     {
-      assert(fg>=0 && bg>=0 && fg<COLORS && bg<COLORS);
+      assert(fg >= 0 && bg >= -1 && fg < COLORS && bg < COLORS);
 
-      return fg*COLORS+bg;
+      if(bg == -1)
+	return fg * COLORS + fg;
+      else if(fg == bg && default_colors_avail)
+	// Pick an arbitrary distinct foreground color to match with
+	// the background.
+	{
+	  if(bg == COLOR_WHITE)
+	    return COLOR_BLACK * COLORS + COLOR_WHITE;
+	  else
+	    return COLOR_WHITE * COLORS + bg;
+	}
+      else
+	return fg * COLORS + bg;
     }
 }
 
@@ -62,16 +77,21 @@
 {
   if(!colors_avail)
     return 0;
-  else if(fg == -1 && bg == -1)
+  else if(fg == -1 && bg == -2)
     return color & A_COLOR;
   else
     {
-      short old_fg=PAIR_NUMBER(color)/COLORS;
-      short old_bg=PAIR_NUMBER(color)%COLORS;
+      short old_fg = PAIR_NUMBER(color) / COLORS;
+      short old_bg = PAIR_NUMBER(color) % COLORS;
+
+      if(old_fg == old_bg && default_colors_avail)
+	old_bg = -1;
 
-      if(fg == -1)
+      if(bg == -1 && !default_colors_avail)
+	return 0;
+      else if(fg == -1)
 	return COLOR_PAIR(get_color_pair(old_fg, bg));
-      else if(bg == -1)
+      else if(bg == -2)
 	return COLOR_PAIR(get_color_pair(fg, old_bg));
       else
 	return COLOR_PAIR(get_color_pair(fg, bg));

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	Sun Sep 25 18:18:23 2005
@@ -20,9 +20,11 @@
 //  Manages color allocation so as to allow any combination of
 //  foreground/background colors to be used.  If there aren't enough
 //  color pairs available to handle all color combinations, this will
-//  act as though no colors are available.  It might be possible to
-//  use colors more effectively; for instance, by ignoring attempts
-//  to define colors whose foreground and background are the same.
+//  act as though no colors are available.  NOTE: colors whose
+//  foreground and background are the same will be reduced to an
+//  arbitrary color of that background; it is expected that the caller
+//  will apply A_INVIS to such colors.  This is done to conserve color
+//  pairs so as to allow the use of the 'default' color.
 
 #ifndef COLORS_H
 #define COLORS_H
@@ -37,7 +39,7 @@
 
 /** \param color attributes containing the starting color value
  *  \param fg the new foreground (-1 to use color)
- *  \param bg the new background (-1 to use color)
+ *  \param bg the new background (-2 to use color; -1 to use the default background)
  *
  *  \return a color pair created by mixing the given foreground
  *  and background into color.

Modified: branches/aptitude-0.3/aptitude/src/vscreen/config/style.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/config/style.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/style.h	Sun Sep 25 18:18:23 2005
@@ -50,7 +50,9 @@
 {
   /** The foreground color to be used. (if negative, no change) */
   short fg;
-  /** The background color to be used. (if negative, no change) */
+  /** The background color to be used. (if -2, no change; if -1, the
+   *  'default' color)
+   */
   short bg;
 
   /** Attributes to set. */
@@ -67,19 +69,19 @@
 
 public:
   /** Initialize an "empty" style. */
-  style():fg(-1), bg(-1), set_attrs(0), clear_attrs(0), flip_attrs(0)
+  style():fg(-1), bg(-2), set_attrs(0), clear_attrs(0), flip_attrs(0)
   {
   }
 
   /** Set the foreground color.  There is no change if the
    *  new foreground color is "empty".
    */
-  void set_fg(short _fg) {if(_fg>=0) fg=_fg;}
+  void set_fg(short _fg) {if(_fg >= 0) fg=_fg;}
 
   /** Set the background color.  There is no change if the
    *  new background color is "empty".
    */
-  void set_bg(short _bg) {if(_bg>=0) bg=_bg;}
+  void set_bg(short _bg) {if(_bg >= -1) bg = _bg;}
 
   /** Set the given attribute(s). */
   void attrs_on(attr_t attrs)
@@ -158,6 +160,8 @@
     rval&=~clear_attrs;
     rval^=flip_attrs;
     rval|=mix_color(0, fg, bg);
+    if(fg == bg)
+      rval |= A_INVIS;
     return rval;
   }
 



More information about the Aptitude-svn-commit mailing list