How to test if console supports ANSI color codes?

Viewed 1752

I use fmt based logger with optionally color prints - which relies on ANSI color commands.

Unfortunately on Windows 10 it is disabled by default. I know how to enable it but I still want to find out how to test whether the console supports ANSI commands or not. Does anybody know?

1 Answers

On Windows you can get/set the ANSI color support by checking/setting the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag with SetConsoleMode() or GetConsoleMode().

There's also the HKEY_CURRENT_USER\Console\VirtualTerminalLevel registry key for global virtual terminal settings. See also https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

On *nix you can use the following ways

Related