diff options
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r-- | src/qmlcompiler/qcoloroutput.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/qmlcompiler/qcoloroutput.cpp b/src/qmlcompiler/qcoloroutput.cpp index f3f5b86d7a..6a99a8007e 100644 --- a/src/qmlcompiler/qcoloroutput.cpp +++ b/src/qmlcompiler/qcoloroutput.cpp @@ -6,7 +6,9 @@ #include <QtCore/qfile.h> #include <QtCore/qhash.h> -#ifndef Q_OS_WIN +#ifdef Q_OS_WIN +#include <qt_windows.h> +#else #include <unistd.h> #endif @@ -75,17 +77,25 @@ private: */ inline bool isColoringPossible() const { + static std::optional<bool> canColor; + if (canColor.has_value()) + return canColor.value(); + #if defined(Q_OS_WIN) - /* Windows doesn't at all support ANSI escape codes, unless - * the user install a "device driver". See the Wikipedia links in the - * class documentation for details. */ - return false; + HANDLE hErr = GetStdHandle(STD_ERROR_HANDLE); + DWORD mode = 0; + + if (GetConsoleMode(hErr, &mode)) + canColor = SetConsoleMode(hErr, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); + else + canColor = false; #else /* We use QFile::handle() to get the file descriptor. It's a bit unsure * whether it's 2 on all platforms and in all cases, so hopefully this layer * of abstraction helps handle such cases. */ - return isatty(fileno(stderr)); + canColor = isatty(fileno(stderr)); #endif + return canColor.value(); } }; |