diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2014-12-29 01:05:21 -0800 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2014-12-29 01:05:21 -0800 |
commit | a6e00f6086467eda633e099d3ed7696bd85184e7 (patch) | |
tree | 4dd3f2fff2fd8d5778a43275922601543f63c297 | |
parent | 6ffcdc1166642a70978a8631364aa8fd93560b62 (diff) | |
download | spack-a6e00f6086467eda633e099d3ed7696bd85184e7.tar.gz spack-a6e00f6086467eda633e099d3ed7696bd85184e7.tar.bz2 spack-a6e00f6086467eda633e099d3ed7696bd85184e7.tar.xz spack-a6e00f6086467eda633e099d3ed7696bd85184e7.zip |
Fix ColorStream
-rw-r--r-- | lib/spack/llnl/util/tty/color.py | 21 | ||||
-rw-r--r-- | lib/spack/spack/spec.py | 3 |
2 files changed, 14 insertions, 10 deletions
diff --git a/lib/spack/llnl/util/tty/color.py b/lib/spack/llnl/util/tty/color.py index 598e9d44f5..81688d7f14 100644 --- a/lib/spack/llnl/util/tty/color.py +++ b/lib/spack/llnl/util/tty/color.py @@ -177,17 +177,20 @@ def cescape(string): class ColorStream(object): def __init__(self, stream, color=None): - self.__class__ = type(stream.__class__.__name__, - (self.__class__, stream.__class__), {}) - self.__dict__ = stream.__dict__ - self.color = color - self.stream = stream + self._stream = stream + self._color = color def write(self, string, **kwargs): - if kwargs.get('raw', False): - super(ColorStream, self).write(string) - else: - cwrite(string, self.stream, self.color) + raw = kwargs.get('raw', False) + raw_write = getattr(self._stream, 'write') + + color = self._color + if self._color is None: + if raw: + color=True + else: + color = self._stream.isatty() + raw_write(colorize(string, color=color)) def writelines(self, sequence, **kwargs): raw = kwargs.get('raw', False) diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 9239bac08f..3386af8d7f 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -1328,7 +1328,8 @@ class Spec(object): def graph(self, **kwargs): N = kwargs.get('node', 'o') # Node character - out = kwargs.get('out', sys.stdout) + color = kwargs.get('color', True) + out = kwargs.get('out', ColorStream(sys.stdout, color=color)) indent = kwargs.get('indent', 0) indent *= ' ' |