mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 16:39:43 +00:00
Support coloured terminal output on Windows
First try the modern Windowsy way, where we can directly query if escape sequences will be processed. The function is available as far back as Windows 2000, but it just won't return the right flag until the Windows version is new enough. If that fails, fall back to the Unixy way, as not all colour-supporting terminal emulators for Windows use the Win32 API to declare that capability. The implementation isn't identical as isatty wasn't available without adding more headers, and we already have Windows.h in this file, so I might as well use the Win32 API instead of its POSIX-compatibility layer.
This commit is contained in:
parent
55c5f2112b
commit
1930bfeabb
1 changed files with 10 additions and 2 deletions
|
@ -256,9 +256,17 @@ namespace Debug
|
|||
private:
|
||||
static bool useColoredOutput()
|
||||
{
|
||||
// Note: cmd.exe in Win10 should support ANSI colors, but in its own way.
|
||||
#if defined(_WIN32)
|
||||
return 0;
|
||||
if (getenv("NO_COLOR"))
|
||||
return false;
|
||||
|
||||
DWORD mode;
|
||||
if (GetConsoleMode(GetStdHandle(STD_ERROR_HANDLE), &mode) && mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
||||
return true;
|
||||
|
||||
// some console emulators may not use the Win32 API, so try the Unixy approach
|
||||
char* term = getenv("TERM");
|
||||
return term && GetFileType(GetStdHandle(STD_ERROR_HANDLE)) == FILE_TYPE_CHAR;
|
||||
#else
|
||||
char* term = getenv("TERM");
|
||||
bool useColor = term && !getenv("NO_COLOR") && isatty(fileno(stderr));
|
||||
|
|
Loading…
Reference in a new issue