diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2015-05-29 17:19:03 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2015-05-29 17:19:03 -0700 |
commit | 9b40d93fc28772d0f3d8c314789ae0aea704b0be (patch) | |
tree | d41b4675df1a42a5ad57026bc6b1bd7e702db3e7 /lib | |
parent | ceecd2ce4152227f413484afad98d576348ec857 (diff) | |
download | spack-9b40d93fc28772d0f3d8c314789ae0aea704b0be.tar.gz spack-9b40d93fc28772d0f3d8c314789ae0aea704b0be.tar.bz2 spack-9b40d93fc28772d0f3d8c314789ae0aea704b0be.tar.xz spack-9b40d93fc28772d0f3d8c314789ae0aea704b0be.zip |
Add ability to force color mode even if terminal is NOT a tty
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/llnl/util/tty/color.py | 8 |
1 files 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): |