2

I would like to use ANSI/VT100 in my C# output (on Linux/Mono PC). But

string colorme = @"\e[31mHello World\e[0m";
Console.WriteLine(colorme);

just results plain-text output in bash (i am using mono). Is it possible to use color codes like \e[31m in C# consolw programs on mono?

AvrDragon
  • 7,139
  • 4
  • 27
  • 42
  • As far as I know, there aren't colour codes in window's command line. I could be wrong, though. You *can* change the colour of the terminal, but not via colour codes. This might be useful: http://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line – Rob Apr 12 '16 at 11:42
  • Did you mean ansi or vt100? Not the same thing, that's where the curses start. Use the Console.ForegroundColor and BackgroundColor properties instead. – Hans Passant Apr 12 '16 at 13:16
  • No, i mean i trying this example in Mono on Linux pc (ubuntu). But it does not work. Typing it in console works fine. – AvrDragon Apr 12 '16 at 13:17

1 Answers1

0

Console.ForegroundColor and Console.BackgroundColor did not work with mono and my console so I was forced to use ANSI coloring.

The main issue is that C# doesn't know how to interpret the \e escape code. Since \e actually represents \x1B we can use the unicode escape code.

string colorme = "\x1b[31mHello World\x1b[0m";
Console.WriteLine(colorme);
Slayjay
  • 3
  • 1
  • 2