0

I'm using the Console API from C# and find a difference between the Console API from Node.js when try to use console commands to change color (`\x1B[31m'):

Using Node.js this code:

 console.log("\x1B[31mTeste");

Prints this: console with Teste in red


When I use this C# code:

Console.Write("\x1B[31mTeste");

I get this output: console with some chars and Teste in default color


Why have this difference?

thur
  • 964
  • 1
  • 15
  • 27

1 Answers1

2

Node uses https://github.com/libuv/libuv to emulate an ANSI console. The normal windows console doesn't support this, therefore trying to do it from C# won't work.

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
  • The console in Windows 10 supports virtual terminal sequences, but it has to be enabled first via WinAPI `GetConsoleMode` and `SetConsoleMode`. In older versions you can use ANSICON or ConEmu, which use DLL injection to hook WinAPI console functions such as `WriteConsole`. – Eryk Sun Sep 06 '17 at 06:58