aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mlog.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-02-15 23:23:40 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2020-02-16 00:26:08 +0530
commitc05b72512299f5aaf33c189a8ff959668f19574f (patch)
tree1e0e474eaaa8e405a5298c0ffa1451d20e08c5d1 /mesonbuild/mlog.py
parent11253a1c3aa3bb8208cae0f04792b26db9b99601 (diff)
downloadmeson-c05b72512299f5aaf33c189a8ff959668f19574f.zip
meson-c05b72512299f5aaf33c189a8ff959668f19574f.tar.gz
meson-c05b72512299f5aaf33c189a8ff959668f19574f.tar.bz2
Split console colourization into a separate function
Use it instead of making a direct call to mlog._windows_ansi().
Diffstat (limited to 'mesonbuild/mlog.py')
-rw-r--r--mesonbuild/mlog.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py
index a30d6b9..b28eca1 100644
--- a/mesonbuild/mlog.py
+++ b/mesonbuild/mlog.py
@@ -40,13 +40,15 @@ def _windows_ansi() -> bool:
# original behavior
return bool(kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON'))
-try:
- if platform.system().lower() == 'windows':
- colorize_console = os.isatty(sys.stdout.fileno()) and _windows_ansi() # type: bool
- else:
- colorize_console = os.isatty(sys.stdout.fileno()) and os.environ.get('TERM') != 'dumb'
-except Exception:
- colorize_console = False
+def setup_console() -> bool:
+ try:
+ if platform.system().lower() == 'windows':
+ return os.isatty(sys.stdout.fileno()) and _windows_ansi()
+ return os.isatty(sys.stdout.fileno()) and os.environ.get('TERM') != 'dumb'
+ except Exception:
+ return False
+
+colorize_console = setup_console()
log_dir = None # type: T.Optional[str]
log_file = None # type: T.Optional[T.TextIO]
log_fname = 'meson-log.txt' # type: str