From 9b40d93fc28772d0f3d8c314789ae0aea704b0be Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 29 May 2015 17:19:03 -0700 Subject: Add ability to force color mode even if terminal is NOT a tty --- lib/spack/llnl/util/tty/color.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/spack/llnl/util/tty/color.py b/lib/spack/llnl/util/tty/color.py index 81688d7f14..22080a7b37 100644 --- a/lib/spack/llnl/util/tty/color.py +++ b/lib/spack/llnl/util/tty/color.py @@ -99,6 +99,10 @@ colors = {'k' : 30, 'K' : 90, # black 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 @@ class ColorStream(object): 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): -- cgit v1.2.3-60-g2f50