diff --git a/lib/spack/llnl/util/tty/color.py b/lib/spack/llnl/util/tty/color.py index 81688d7f14d..22080a7b37f 100644 --- a/lib/spack/llnl/util/tty/color.py +++ b/lib/spack/llnl/util/tty/color.py @@ -99,6 +99,10 @@ def __init__(self, message): color_re = r'@(?:@|\.|([*_])?([a-zA-Z])?(?:{((?:[^}]|}})*)})?)' +# Force color even if stdout is not a tty. +_force_color = False + + class match_to_ansi(object): def __init__(self, color=True): self.color = color @@ -162,7 +166,7 @@ def cwrite(string, stream=sys.stdout, color=None): then it will be set based on stream.isatty(). """ if color is None: - color = stream.isatty() + color = stream.isatty() or _force_color stream.write(colorize(string, color=color)) @@ -189,7 +193,7 @@ def write(self, string, **kwargs): if raw: color=True else: - color = self._stream.isatty() + color = self._stream.isatty() or _force_color raw_write(colorize(string, color=color)) def writelines(self, sequence, **kwargs):