Allow/Default use of ANSI color codes on Windows
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
**Description**
With a little snippet during initialization, Windows 10 and newer support ANSI color codes out of the box:
```c++
#ifdef _WIN32
HANDLE outputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD mode = 0;
if (GetConsoleMode(outputHandle, &mode))
{
mode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(outputHandle, mode);
}
#endif // _WIN32
```
The `CATCH_INTERNAL_HAS_ISATTY` is somewhat malformed - Windows has `isatty` too (in header `#include ` instead of `#include `) - but what it doesn't have is `STDOUT_FILENO` so the portable solution for that is `isatty(fileno(stdout))`.
On Windows 10 or newer (or in case that covers ALL support Windows platforms: For every Windows-platform in general), the ANSI color code support should be preferred unconditionally over the legacy text attribute API.
**Additional context**
This avoids a lot of issues you'd otherwise have with the Windows terminal handling - among others that setting colors via `SetConsoleTextAttribute` on Windows breaks horribly when the application under test is enabling output buffering for `stdout` as the legacy API for color codes only every works as long as `stdout` is byte-buffered only.
Contributor guide
Assessment
This issue has not been assessed yet.