Split console colourization into a separate function

Use it instead of making a direct call to mlog._windows_ansi().
pull/6634/head
Nirbheek Chauhan 5 years ago committed by Nirbheek Chauhan
parent 11253a1c3a
commit c05b725122
  1. 3
      mesonbuild/mesonlib.py
  2. 16
      mesonbuild/mlog.py

@ -65,8 +65,7 @@ def git(cmd: T.List[str], workingdir: str, **kwargs) -> subprocess.CompletedProc
# Sometimes git calls git recursively, such as `git submodule update
# --recursive` which will be without the above workaround, so set the
# console mode again just in case.
if platform.system().lower() == 'windows':
mlog._windows_ansi()
mlog.setup_console()
return pc

@ -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

Loading…
Cancel
Save