tag 337689 + patch
stop

Patch attached, note that it does limit access to the first 256 colors,
however I'd be willing to fix that in a more reasonable manner...  As
soon as someone shows me a terminal with more then 256 colors supported.

Zephaniah E. Hull.
diff -ur orig/aptitude-0.4.0/src/vscreen/config/colors.cc 
aptitude-0.4.0/src/vscreen/config/colors.cc
--- orig/aptitude-0.4.0/src/vscreen/config/colors.cc    2005-10-05 
02:55:22.000000000 -0400
+++ aptitude-0.4.0/src/vscreen/config/colors.cc 2005-11-07 22:31:16.000000000 
-0500
@@ -23,31 +23,26 @@
 
 static bool colors_avail=false;
 static bool default_colors_avail = false;
+static short palette[256][256];
+static short cur_index, max_colors;
 
-// Simplistic allocation scheme for colors: (fg,bg) => fg*COLORS+bg
+// Less simplistic allocation scheme for colors.
 
 void init_colors()
 {
-  if(COLORS == 0 || COLOR_PAIRS < COLORS * COLORS)
+  if (COLORS == 0)
     return;
 
   colors_avail=true;
   default_colors_avail = (use_default_colors() != ERR);
-
-  for(short fg=0; fg<COLORS; ++fg)
-    for(short bg=0; bg<COLORS; ++bg)
-      {
-       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..
-         ;
-         /*assume_default_colors(0, 0);*/
-       else
-         init_pair(fg*COLORS+bg, fg, bg);
-      }
+  cur_index = 1;
+  max_colors = COLORS;
+  if (max_colors > 256)
+      max_colors = 256;
+
+  for(short fg=0; fg<max_colors; ++fg)
+    for(short bg=0; bg<max_colors; ++bg)
+      palette[fg][bg] = -1;
 }
 
 int get_color_pair(short fg, short bg)
@@ -56,21 +51,22 @@
     return 0;
   else
     {
-      assert(fg >= 0 && bg >= -1 && fg < COLORS && bg < COLORS);
+      assert(fg >= 0 && bg >= -1 && fg < max_colors && bg < max_colors);
+
+      if (bg == -1)
+       bg = fg;
 
-      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 (palette[fg][bg] == -1)
        {
-         if(bg == COLOR_WHITE)
-           return COLOR_BLACK * COLORS + COLOR_WHITE;
+         palette[fg][bg] = cur_index++;
+         assert(cur_index < COLOR_PAIRS);
+         if (fg == bg && default_colors_avail)
+           init_pair(palette[fg][bg], fg, -1);
          else
-           return COLOR_WHITE * COLORS + bg;
+           init_pair(palette[fg][bg], fg, bg);
        }
-      else
-       return fg * COLORS + bg;
+
+      return palette[fg][bg];
     }
 }
 
@@ -82,8 +78,9 @@
     return color & A_COLOR;
   else
     {
-      short old_fg = PAIR_NUMBER(color) / COLORS;
-      short old_bg = PAIR_NUMBER(color) % COLORS;
+      short old_fg, old_bg;
+
+      pair_content (PAIR_NUMBER(color), &old_fg, &old_bg);
 
       if(old_fg == old_bg && default_colors_avail)
        old_bg = -1;
Only in orig/aptitude-0.4.0/src/vscreen/config: .colors.cc.swp

Reply via email to