[Mono-list] console color again

InTheMood inthemood at gmx.net
Wed Nov 16 12:54:08 EST 2005


hi,
finally i found the way how to color the output. coloring the console 
output works fine on windows.

output looks like this:

<code>--------------------------------------------------------------------------------------------
All the foreground colors on a constant black background.
  (Black on black is not readable.)

 0: This is foreground color Black.
 1: This is foreground color DarkBlue.
and so on

A constant white foreground on all the background colors.
  (White on white is not readable.)

 0: This is background color Black.
 1: This is background color DarkBlue.
and so on
</code>--------------------------------------------------------------------------------------------

nice colored... :)

but on linux the following eception is thrown:

<code>--------------------------------------------------------------------------------------------
debian:/tmp# mono Test.exe

All the foreground colors on a constant black background.
  (Black on black is not readable.)

 0:
Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
in <0x003c9> System.String:FormatHelper (System.Text.StringBuilder 
result, IFormatProvider provider, System.String format, System.Object[] 
args)
in <0x0002b> System.String:Format (IFormatProvider provider, 
System.String format, System.Object[] args)
in <0x00037> System.String:Format (System.String format, System.Object arg0)
in <0x00034> System.TermInfoDriver:set_BackgroundColor (ConsoleColor value)
in <0x0002f> System.ConsoleDriver:set_BackgroundColor (ConsoleColor value)
in <0x0000a> System.Console:set_BackgroundColor (ConsoleColor value)
in <0x0007f> Test.MainClass:Main (System.String[] args)
</code>--------------------------------------------------------------------------------------------

thats the piece of code:

<code>--------------------------------------------------------------------------------------------
        String nl = Environment.NewLine;
        String[] colorNames = ConsoleColor.GetNames(typeof(ConsoleColor));

        Console.WriteLine("{0}All the foreground colors on a constant 
black background.", nl);
        Console.WriteLine("  (Black on black is not readable.){0}", nl);

        for (int x = 0; x < colorNames.Length; x++)
        {
            Console.Write("{0,2}: ", x);
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = 
(ConsoleColor)Enum.Parse(typeof(ConsoleColor), colorNames[x]);
            Console.Write("This is foreground color {0}.", colorNames[x]);
            Console.ResetColor();
            Console.WriteLine();
        }
            // 
---------------------------------------------------------------------------------------
        Console.WriteLine("{0}A constant white foreground on all the 
background colors.", nl);
        Console.WriteLine("  (White on white is not readable.){0}", nl);

        for (int x = 0; x < colorNames.Length; x++)
        {
            Console.Write("{0,2}: ", x);
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = 
(ConsoleColor)Enum.Parse(typeof(ConsoleColor), colorNames[x]);
            Console.Write("This is background color {0}.", colorNames[x]);
            Console.ResetColor();
            Console.WriteLine();
        }
<code>--------------------------------------------------------------------------------------------

wheres my fault? or can this class only be used on windows machines?

best regards






More information about the Mono-list mailing list