2007-04-24 Jeffrey Stedfast <fejj@novell.com>
authorJeffrey Stedfast <fejj@novell.com>
Tue, 24 Apr 2007 21:26:38 +0000 (21:26 -0000)
committerJeffrey Stedfast <fejj@novell.com>
Tue, 24 Apr 2007 21:26:38 +0000 (21:26 -0000)
Fixes the last of the bugs listed in bug #77525

* TermInfoDriver.cs (ctor): For known terminal types, set color16
to true (since we know they support 16 colours).
(Init): set the setlfgcolor and setlbgcolor format strings.
(BackgroundColor): Use the appropriate formatter string for
setting the bgcolor.
(ForegroundColor): Use the appropriate formatter string for
setting the fgcolor.
(TranslateColor): Now takes (and sets appropriately) an output
'bool light' argument.

svn path=/trunk/mcs/; revision=76226

mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/TermInfoDriver.cs

index cf48d85974e6c4abd61caee20d649cea54b6789f..126202258288fb111ae951d25daeb77b25715557 100644 (file)
@@ -1,3 +1,17 @@
+2007-04-24  Jeffrey Stedfast  <fejj@novell.com>
+
+       Fixes the last of the bugs listed in bug #77525
+
+       * TermInfoDriver.cs (ctor): For known terminal types, set color16
+       to true (since we know they support 16 colours).
+       (Init): set the setlfgcolor and setlbgcolor format strings.
+       (BackgroundColor): Use the appropriate formatter string for
+       setting the bgcolor.
+       (ForegroundColor): Use the appropriate formatter string for
+       setting the fgcolor.
+       (TranslateColor): Now takes (and sets appropriately) an output
+       'bool light' argument.
+
 2007-04-24  Marek Habersack  <mhabersack@novell.com>
 
        * TermInfoDriver.cs: don't include debug stuff by default - it
index 8be350141112979de99f431b7396253a78bdc93a..bceb0c514bea07cec2485c5266371f8fbcf8e1b0 100644 (file)
@@ -76,8 +76,11 @@ namespace System {
                string cursorAddress;
                ConsoleColor fgcolor = ConsoleColor.White;
                ConsoleColor bgcolor = ConsoleColor.Black;
-               string setafcolor; // TODO: use setforeground/setbackground if available for better
-               string setabcolor; // color mapping.
+               bool color16 = false; // terminal supports 16 colors
+               string setlfgcolor;
+               string setlbgcolor;
+               string setfgcolor;
+               string setbgcolor;
                bool noGetPosition;
                Hashtable keymap;
                ByteMatcher rootmap;
@@ -130,15 +133,17 @@ namespace System {
                public TermInfoDriver (string term)
                {
 #if DEBUG
-                       //File.Delete ("console.log");
+                       File.Delete ("console.log");
                        logger = new StreamWriter (File.OpenWrite ("console.log"));
 #endif
                        this.term = term;
 
                        if (term == "xterm") {
                                reader = new TermInfoReader (term, KnownTerminals.xterm);
+                               color16 = true;
                        } else if (term == "linux") {
                                reader = new TermInfoReader (term, KnownTerminals.linux);
+                               color16 = true;
                        } else {
                                string filename = SearchTerminfo (term);
                                if (filename != null)
@@ -185,8 +190,12 @@ namespace System {
 
                        origPair = reader.Get (TermInfoStrings.OrigPair);
                        origColors = reader.Get (TermInfoStrings.OrigColors);
-                       setafcolor = MangleParameters (reader.Get (TermInfoStrings.SetAForeground));
-                       setabcolor = MangleParameters (reader.Get (TermInfoStrings.SetABackground));
+                       setfgcolor = MangleParameters (reader.Get (TermInfoStrings.SetAForeground));
+                       setbgcolor = MangleParameters (reader.Get (TermInfoStrings.SetABackground));
+                       // lighter fg colours are 90 -> 97 rather than 30 -> 37
+                       setlfgcolor = color16 ? setfgcolor.Replace ("[3", "[9") : setfgcolor;
+                       // lighter bg colours are 100 -> 107 rather than 40 -> 47
+                       setlbgcolor = color16 ? setbgcolor.Replace ("[4", "[10") : setbgcolor;
                        string resetColors = (origColors == null) ? origPair : origColors;
                        if (resetColors != null)
                                endString += resetColors;
@@ -246,35 +255,63 @@ namespace System {
                        return str.Replace ("%p2%d", "{1}");
                }
 
-               static int TranslateColor (ConsoleColor desired)
+               static int TranslateColor (ConsoleColor desired, out bool light)
                {
                        switch (desired) {
+                       // Dark colours
                        case ConsoleColor.Black:
-                       case ConsoleColor.DarkGray:
+                               light = false;
                                return 0;
-                       case ConsoleColor.DarkBlue:
-                       case ConsoleColor.Blue:
-                               return 4;
+                       case ConsoleColor.DarkRed:
+                               light = false;
+                               return 1;
                        case ConsoleColor.DarkGreen:
-                       case ConsoleColor.Green:
+                               light = false;
                                return 2;
+                       case ConsoleColor.DarkYellow:
+                               light = false;
+                               return 3;
+                       case ConsoleColor.DarkBlue:
+                               light = false;
+                               return 4;
+                       case ConsoleColor.DarkMagenta:
+                               light = false;
+                               return 5;
                        case ConsoleColor.DarkCyan:
-                       case ConsoleColor.Cyan:
+                               light = false;
                                return 6;
-                       case ConsoleColor.DarkRed:
+                       case ConsoleColor.Gray:
+                               light = false;
+                               return 7;
+                       // Light colours
+                       case ConsoleColor.DarkGray:
+                               light = true;
+                               return 0;
                        case ConsoleColor.Red:
+                               light = true;
                                return 1;
-                       case ConsoleColor.DarkMagenta:
-                       case ConsoleColor.Magenta:
-                               return 5;
-                       case ConsoleColor.DarkYellow:
+                       case ConsoleColor.Green:
+                               light = true;
+                               return 2;
                        case ConsoleColor.Yellow:
+                               light = true;
                                return 3;
-                       case ConsoleColor.Gray:
+                       case ConsoleColor.Blue:
+                               light = true;
+                               return 4;
+                       case ConsoleColor.Magenta:
+                               light = true;
+                               return 5;
+                       case ConsoleColor.Cyan:
+                               light = true;
+                               return 6;
                        case ConsoleColor.White:
+                               light = true;
                                return 7;
                        }
 
+                       light = false;
+
                        return 0;
                }
 
@@ -380,7 +417,14 @@ namespace System {
                                }
 
                                bgcolor = value;
-                               WriteConsole (String.Format (setabcolor, TranslateColor (value)));
+
+                               bool light;
+                               int colour = TranslateColor (value, out light);
+
+                               if (light)
+                                       WriteConsole (String.Format (setlbgcolor, colour));
+                               else
+                                       WriteConsole (String.Format (setbgcolor, colour));
                        }
                }
 
@@ -398,7 +442,14 @@ namespace System {
                                }
 
                                fgcolor = value;
-                               WriteConsole (String.Format (setafcolor, TranslateColor (value)));
+
+                               bool light;
+                               int colour = TranslateColor (value, out light);
+
+                               if (light)
+                                       WriteConsole (String.Format (setlfgcolor, colour));
+                               else
+                                       WriteConsole (String.Format (setfgcolor, colour));
                        }
                }