Windows console with ANSI colors handling

None of the answers on this page mention an important aspect of the new support for ANSI Terminal Control which was added to the Windows 10 console host in build 16257 (and later). Namely, it's n̲o̲t̲ e̲n̲a̲b̲l̲e̲d̲ by default. Unless the specific software you're using enables ANSI processing by calling the SetConsoleMode API with the ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x0004) flag, you won't see colors or get ANSI processing for that application.

ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
https://docs.microsoft.com/windows/console/setconsolemode

When writing with WriteFile or WriteConsole, characters are parsed for VT100 and similar control character sequences that control cursor movement, color/font mode, and other operations that can also be performed via the existing Console APIs. For more information, see Console Virtual Terminal Sequences.

I'm guessing the reason the examples shown on this page work is that, apparently the echo command (or perhaps the batch-processing part of CMD.EXE or conhost) enables ANSI processing by calling the API just mentioned. But many other tools or executables that write to stdin or stdout might not do this, in which case you won't see color for those processes.

Fortunately, the global default can be changed from opt-in to opt-out. The registry key at HKEY_CURRENT_USER\Console\VirtualTerminalLevel sets the global default behavior for processing ANSI escape sequences. Create a DWORD key (if necessary) and set its value to 1 to globally enable (or 0 to disable`) ANSI processing by default.

[HKEY_CURRENT_USER\Console]
"VirtualTerminalLevel"=dword:00000001

Note that this registry setting controls a default, meaning that it only affects console apps which don't explicitly manipulate the console mode by calling SetConsoleMode(...). It follows that, while the registry value may help enable ANSI for console-mode-oblivious apps, it will have no effect on any console-mode-savvy app which (for some reason) may explicitly disable ANSI.

enter image description here


ConEmu supports ANSI X3.64 with Xterm 256 color extension. I'm the author of this console emulator.

Ansi sequences are handled for all processes, running in ConEmu tabs.

AFAIK, ConEmu supports more codes, than Ansicon.

ConEmu and ANSI X3.64 / Xterm 256 colors