Skip to content
Snippets Groups Projects
Commit dfd0440a authored by Todd Gamblin's avatar Todd Gamblin
Browse files

Color tweaks for find.

parent a63482be
No related branches found
No related tags found
No related merge requests found
import collections
import argparse
from StringIO import StringIO
import spack
import spack.spec
import spack.packages as packages
import spack.colify
from spack.color import *
from spack.colify import colify
description ="Find installed spack packages"
......@@ -21,7 +24,7 @@ def setup_parser(subparser):
# TODO: move this and colify to tty.
def hline(label, char):
def hline(label, char, color=''):
max_width = 64
cols, rows = spack.colify.get_terminal_size()
if not cols:
......@@ -31,9 +34,18 @@ def hline(label, char):
cols = min(max_width, cols)
label = str(label)
out = char * 2 + " " + label + " "
out += (cols - len(out)) * char
return out
prefix = char * 2 + " " + label + " "
suffix = (cols - len(prefix)) * char
out = StringIO()
if color:
prefix = char * 2 + " " + color + cescape(label) + "@. "
cwrite(prefix, stream=out, color=True)
else:
out.write(prefix)
out.write(suffix)
return out.getvalue()
def find(parser, args):
......@@ -56,14 +68,14 @@ def hasher():
# Traverse the index and print out each package
for architecture in index:
print hline(architecture, "=")
print hline(architecture, "=", spack.spec.architecture_color)
for compiler in index[architecture]:
print hline(compiler, "-")
print hline(compiler, "-", spack.spec.compiler_color)
specs = index[architecture][compiler]
specs.sort()
abbreviated = [s.format('$_$@$+$#') for s in specs]
abbreviated = [s.format('$_$@$+$#', color=True) for s in specs]
if args.paths:
# Print one spec per line along with prefix path
......@@ -76,7 +88,7 @@ def hasher():
elif args.full_specs:
for spec in specs:
print spec.tree(indent=4, format='$_$@$+'),
print spec.tree(indent=4, format='$_$@$+', color=True),
else:
for abbrv in abbreviated:
print " %s" % abbrv
......@@ -83,15 +83,23 @@
from spack.util.string import *
# Convenient names for color formats so that other things can use them
compiler_color = '@g'
version_color = '@c'
architecture_color = '@m'
enabled_variant_color = '@B'
disabled_variant_color = '@r'
dependency_color = '@.'
"""This map determines the coloring of specs when using color output.
We make the fields different colors to enhance readability.
See spack.color for descriptions of the color codes. """
color_formats = {'%' : '@g', # compiler
'@' : '@c', # version
'=' : '@m', # architecture
'+' : '@B', # enable variant
'~' : '@r', # disable variant
'^' : '@.'} # dependency
color_formats = {'%' : compiler_color,
'@' : version_color,
'=' : architecture_color,
'+' : enabled_variant_color,
'~' : disabled_variant_color,
'^' : dependency_color }
"""Regex used for splitting by spec field separators."""
separators = '[%s]' % ''.join(color_formats.keys())
......@@ -823,27 +831,34 @@ def format(self, format_string='$_$@$%@$+$=', **kwargs):
of the package, but no dependencies, arch, or compiler.
"""
color = kwargs.get('color', False)
length = len(format_string)
out = StringIO()
escape = compiler = False
def write(s, c):
if color:
f = color_formats[c] + cescape(s) + '@.'
cwrite(f, stream=out, color=color)
else:
out.write(s)
for i, c in enumerate(format_string):
if escape:
if c == '_':
out.write(self.name)
elif c == '@':
if self.versions and self.versions != VersionList([':']):
out.write(c + str(self.versions))
write(c + str(self.versions), c)
elif c == '%':
if self.compiler:
out.write(c + str(self.compiler.name))
write(c + str(self.compiler.name), c)
compiler = True
elif c == '+':
if self.variants:
out.write(str(self.variants))
write(str(self.variants), c)
elif c == '=':
if self.architecture:
out.write(c + str(self.architecture))
write(c + str(self.architecture), c)
elif c == '#':
if self.dependencies:
out.write('-' + self.dependencies.sha1()[:6])
......@@ -854,7 +869,7 @@ def format(self, format_string='$_$@$%@$+$=', **kwargs):
elif compiler:
if c == '@':
if self.compiler and self.compiler.versions:
out.write(c + str(self.compiler.versions))
write(c + str(self.compiler.versions), '%')
elif c == '$':
escape = True
else:
......@@ -870,8 +885,6 @@ def format(self, format_string='$_$@$%@$+$=', **kwargs):
out.write(c)
result = out.getvalue()
if color:
result = colorize_spec(result)
return result
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment