From 267322450df4f0d702a8baa4f9c7be083e4a9661 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Tue, 1 Feb 2022 12:36:28 +0100 Subject: Disable remote_build.py's ANSI codes if the terminal doesn't support them --- scripts/remote_build.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'scripts/remote_build.py') diff --git a/scripts/remote_build.py b/scripts/remote_build.py index e83f95d8d..756748853 100644 --- a/scripts/remote_build.py +++ b/scripts/remote_build.py @@ -6,10 +6,23 @@ from pathlib import Path # {{{1 misc -------------------------------------------------------------------- +# Disables output of ANSI codes if the terminal doesn't support them +if os.name == "nt": + from ctypes import windll, c_int, byref + stdout_handle = windll.kernel32.GetStdHandle(c_int(-11)) + mode = c_int(0) + windll.kernel32.GetConsoleMode(c_int(stdout_handle), byref(mode)) + ansi_on = (mode.value & 4) != 0 +else: + ansi_on = True + #------------------------------------------------------------------------------- def _header(*args, ansi=96): - print(f"\x1b[{ansi}m##", *args, end="") - print("\x1b[0m") + if ansi_on: + print(f"\x1b[{ansi}m##", *args, end="") + print("\x1b[0m") + else: + print("\n##", *args) #------------------------------------------------------------------------------- def _run_checked(cmd, *args, **kwargs): -- cgit v1.2.3