slang-users mailing list

[2002 Date Index] [2002 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

setf and setb are in GBR (1=blue, 4=red)


Hello!

I recently got a report that GNU Mignight Commander 4.6.0-pre1 compiled
with S-Lang has red panels on QNX Neutrino.  It turned out that just
running "TERM=qansi mc" is enough to make mc red.  If mc is compiled with
ncurses, it stays blue with TERM=qansi.

Further investigation demonstrated that the removal of setaf and setab
capabilities from the xterm entry in terminfo has the same effect on the
mc color.

The terminfo manual (ncurses 5.2) says:

The setaf/setab and setf/setb capabilities take a single numeric argument
each...
                    black     COLOR_BLACK       0     0, 0, 0
                    red       COLOR_RED         1     max,0,0
                    ...
                    blue      COLOR_BLUE        4     0,0,max

But that's not what ncurses does!  It applies toggled_colors() function to
the color if it was defined by setf or setb, as opposed to setaf/setab.  
That function swaps bytes so that blue becomes 1 and red becomes 4 before
the color is passed as arguments to the format interpreter.

This patch makes the same for S-Lang 1.4.6.

CC: to Thomas E. Dickey as the maintainer of ncurses - please consider 
fixing the termcap manual.  You must know more that you write there.

==================================
--- slang/sldisply.c
+++ slang/sldisply.c
@@ -161,6 +161,13 @@ static Ansi_Color_Type Ansi_Color_Map[JM
      {RGB(0, 1, 0, 1, 1, 1), SLTT_REV_MASK, NULL}
 };
 
+static int Is_Color_BGR = 0; /* 0 if least significant bit is blue, not red */
+#define COLOR_ARG(color) (Is_Color_BGR ? RGB_to_BGR[color] : color)
+static int RGB_to_BGR[] =
+{
+     0, 4, 2, 6, 1, 5, 3, 7
+};
+
 static char *Color_Fg_Str = "\033[3%dm";
 static char *Color_Bg_Str = "\033[4%dm";
 static char *Default_Color_Fg_Str = "\033[39m";
@@ -1332,7 +1339,7 @@ static void write_attributes (SLtt_Char_
 	     if (fg0 == SLSMG_COLOR_DEFAULT)
 	       tt_write_string (Default_Color_Fg_Str);
 	     else
-	       tt_printf (Color_Fg_Str, fg0, 0);
+	       tt_printf (Color_Fg_Str, COLOR_ARG(fg0), 0);
 	  }
 
 	if (unknown_attributes
@@ -1341,7 +1348,7 @@ static void write_attributes (SLtt_Char_
 	     if (bg0 == SLSMG_COLOR_DEFAULT)
 	       tt_write_string (Default_Color_Bg_Str);
 	     else
-	       tt_printf (Color_Bg_Str, bg0, 0);
+	       tt_printf (Color_Bg_Str, COLOR_ARG(bg0), 0);
 	  }
      }
 
@@ -2367,6 +2374,7 @@ int SLtt_initialize (char *term)
      {
 	Color_Fg_Str = SLtt_tgetstr ("Sf");   /* setf */
 	Color_Bg_Str = SLtt_tgetstr ("Sb");   /* setb */
+	Is_Color_BGR = 1;
      }
 
    if ((Max_Terminfo_Colors = SLtt_tgetnum ("Co")) < 0)
==================================

-- 
Regards,
Pavel Roskin


[2002 date index] [2002 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]