aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsabella Muerte <63051+slurps-mad-rips@users.noreply.github.com>2018-04-30 04:45:42 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2018-05-01 20:17:14 +0300
commit91c1cc6f9e5687360b982993ac8926cf0787a66d (patch)
tree03fbebae61dc3836f4a41cf909fcd0d017da69bb
parentd3ff7d44abbf8246c2bea6ca5ef930a22d07de7f (diff)
downloadmeson-91c1cc6f9e5687360b982993ac8926cf0787a66d.zip
meson-91c1cc6f9e5687360b982993ac8926cf0787a66d.tar.gz
meson-91c1cc6f9e5687360b982993ac8926cf0787a66d.tar.bz2
Add VT100 ANSI escape sequences for Windows 10.
This change still relies on the older 'ANSICON' environment check as a fallback, in the event we're on "not Windows 10". (Calling `SetConsoleMode` with unsupported values results in a 0 being returned)
-rw-r--r--mesonbuild/mlog.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py
index afefaa6..d17b889 100644
--- a/mesonbuild/mlog.py
+++ b/mesonbuild/mlog.py
@@ -19,8 +19,22 @@ from contextlib import contextmanager
information about Meson runs. Some output goes to screen,
some to logging dir and some goes to both."""
+def _windows_ansi():
+ from ctypes import windll, byref
+ from ctypes.wintypes import DWORD
+
+ kernel = windll.kernel32
+ stdout = kernel.GetStdHandle(-11)
+ mode = DWORD()
+ if not kernel.GetConsoleMode(stdout, byref(mode)):
+ return False
+ # ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0x4
+ # If the call to enable VT processing fails (returns 0), we fallback to
+ # original behavior
+ return kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON')
+
if platform.system().lower() == 'windows':
- colorize_console = os.isatty(sys.stdout.fileno()) and os.environ.get('ANSICON')
+ colorize_console = os.isatty(sys.stdout.fileno()) and _windows_ansi()
else:
colorize_console = os.isatty(sys.stdout.fileno()) and os.environ.get('TERM') != 'dumb'
log_dir = None