help="The meson build directory")
options = parser.parse_args()
- if options.no_color:
+ if options.no_color or not Colors.can_enable():
Colors.disable()
if not os.path.exists(options.builddir):
-import argparse
import os
import sys
+import shlex
import shutil
+import argparse
+import platform
import subprocess
-import shlex
ROOTDIR = os.path.abspath(os.path.dirname(__file__))
force_disable = False
+ 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
+ # Try setting ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
+ # If that fails (returns 0), we disable colors
+ return kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON')
+
+ @classmethod
+ def can_enable(cls):
+ if not os.isatty(sys.stdout.fileno()):
+ return False
+ if platform.system().lower() == 'windows':
+ return cls._windows_ansi()
+ return os.environ.get('TERM') != 'dumb'
+
@classmethod
def disable(cls):
cls.HEADER = ''
def git(*args, repository_path='.'):
return subprocess.check_output(["git"] + list(args), cwd=repository_path,
- ).decode()
+ stdin=subprocess.DEVNULL,
+ stderr=subprocess.STDOUT).decode()
def accept_command(commands):
"""Search @commands and returns the first found absolute path."""
help="Use a android repo manifest to sync repositories"
" Note that it will let all repositories in detached state")
options = parser.parse_args()
- if options.no_color:
+ if options.no_color or not Colors.can_enable():
Colors.disable()
if options.no_interaction: