From b27fbfb379926cf1df81d6c4ae644377d3b95b82 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 26 Oct 2018 22:19:11 -0700 Subject: config: `spack config blame` now colors filenames in config output (#9656) - it was hard to distinguish all-gray filenames - added rotating colors to `spack config blame` --- lib/spack/spack/util/spack_yaml.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/util/spack_yaml.py b/lib/spack/spack/util/spack_yaml.py index ee4b37388c..a1966664d9 100644 --- a/lib/spack/spack/util/spack_yaml.py +++ b/lib/spack/spack/util/spack_yaml.py @@ -275,6 +275,8 @@ class LineAnnotationDumper(OrderedLineDumper): def __init__(self, *args, **kwargs): super(LineAnnotationDumper, self).__init__(*args, **kwargs) del _annotations[:] + self.colors = 'KgrbmcyGRBMCY' + self.filename_colors = {} def process_scalar(self): super(LineAnnotationDumper, self).process_scalar() @@ -301,7 +303,15 @@ class LineAnnotationDumper(OrderedLineDumper): # append annotations at the end of each line if self.saved: mark = self.saved._start_mark - ann = '@K{%s}' % mark.name + + color = self.filename_colors.get(mark.name) + if not color: + ncolors = len(self.colors) + color = self.colors[len(self.filename_colors) % ncolors] + self.filename_colors[mark.name] = color + + fmt = '@%s{%%s}' % color + ann = fmt % mark.name if mark.line is not None: ann += ':@c{%s}' % (mark.line + 1) _annotations.append(colorize(ann)) -- cgit v1.2.3-70-g09d2