Your program must be compiled for /platform:x64 if you are using AnsiCon x64 and /platform:x86 if you are using AnsiCon x86 / 32 bit. The exact reason is the mystery ...
Originally, I thought you needed all of this:
You need to capture StandardOutput and let Console.WriteLine assume that you are writing the file, not the console, and using ASCII encoding.
Here's how it will work:
var stdout = Console.OpenStandardOutput(); var con = new StreamWriter(stdout, Encoding.ASCII); con.AutoFlush = true; Console.SetOut(con); Console.WriteLine("\x1b[36mTEST\x1b[0m");
.Net Console.WriteLine uses the internal __ConsoleStream , which checks if Console.Out file descriptor or a console descriptor. By default, it uses a console descriptor and therefore writes to the console by calling WriteConsoleW . In the notes you will find:
Although an application can use WriteConsole in ANSI mode to write ANSI characters, consoles do not support ANSI escape sequences. However, some functions provide equivalent functionality. For more information, see SetCursorPos, SetConsoleTextAttribute, and GetConsoleCursorInfo.
To write bytes directly to the console without WriteConsoleW , a simple file / stream descriptor, which will be executed by calling OpenStandardOutput , will OpenStandardOutput . By packing this stream into StreamWriter so that we can install it again using Console.SetOut , we are done. Byte sequences are sent to an OutputStream and matched by AnsiCon.
Please note that this can only be used with the appropriate terminal emulator, for example AnsiCon, as shown below:

source share