summaryrefslogtreecommitdiff
path: root/lib/spack/llnl/util/tty/colify.py
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2015-10-12 14:44:41 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2015-10-12 14:44:41 -0700
commit2c81875019803af7b7f08b070f37c45e51a3c7d5 (patch)
tree17c9e29b2c130d14550dbfef58be757d45d2b0e4 /lib/spack/llnl/util/tty/colify.py
parent5dd39bfca56e984089236f4383d3ad348e1b0a54 (diff)
downloadspack-2c81875019803af7b7f08b070f37c45e51a3c7d5.tar.gz
spack-2c81875019803af7b7f08b070f37c45e51a3c7d5.tar.bz2
spack-2c81875019803af7b7f08b070f37c45e51a3c7d5.tar.xz
spack-2c81875019803af7b7f08b070f37c45e51a3c7d5.zip
Fix bug in colify color handling.
Diffstat (limited to 'lib/spack/llnl/util/tty/colify.py')
-rw-r--r--lib/spack/llnl/util/tty/colify.py18
1 files changed, 4 insertions, 14 deletions
diff --git a/lib/spack/llnl/util/tty/colify.py b/lib/spack/llnl/util/tty/colify.py
index 66c52c3968..db928444c7 100644
--- a/lib/spack/llnl/util/tty/colify.py
+++ b/lib/spack/llnl/util/tty/colify.py
@@ -33,8 +33,7 @@ import struct
from StringIO import StringIO
from llnl.util.tty import terminal_size
-from llnl.util.tty.color import clen
-
+from llnl.util.tty.color import clen, cextra
class ColumnConfig:
def __init__(self, cols):
@@ -42,7 +41,6 @@ class ColumnConfig:
self.line_length = 0
self.valid = True
self.widths = [0] * cols # does not include ansi colors
- self.cwidths = [0] * cols # includes ansi colors
def __repr__(self):
attrs = [(a,getattr(self, a)) for a in dir(self) if not a.startswith("__")]
@@ -66,8 +64,6 @@ def config_variable_cols(elts, console_width, padding, cols=0):
# Get a bound on the most columns we could possibly have.
# 'clen' ignores length of ansi color sequences.
lengths = [clen(e) for e in elts]
- clengths = [len(e) for e in elts]
-
max_cols = max(1, console_width / (min(lengths) + padding))
max_cols = min(len(elts), max_cols)
@@ -85,7 +81,6 @@ def config_variable_cols(elts, console_width, padding, cols=0):
if conf.widths[col] < (length + p):
conf.line_length += length + p - conf.widths[col]
conf.widths[col] = length + p
- conf.cwidths[col] = clengths[i] + p
conf.valid = (conf.line_length < console_width)
try:
@@ -118,7 +113,6 @@ def config_uniform_cols(elts, console_width, padding, cols=0):
config = ColumnConfig(cols)
config.widths = [max_len] * cols
- config.cwidths = [max_clen] * cols
return config
@@ -147,9 +141,6 @@ def colify(elts, **options):
method=<string> Method to use to fit columns. Options are variable or uniform.
Variable-width columns are tighter, uniform columns are all the
same width and fit less data on the screen.
-
- len=<func> Function to use for calculating string length.
- Useful for ignoring ansi color. Default is 'len'.
"""
# Get keyword arguments or set defaults
cols = options.pop("cols", 0)
@@ -199,9 +190,6 @@ def colify(elts, **options):
raise ValueError("method must be one of: " + allowed_methods)
cols = config.cols
- formats = ["%%-%ds" % width for width in config.cwidths[:-1]]
- formats.append("%s") # last column has no trailing space
-
rows = (len(elts) + cols - 1) / cols
rows_last_col = len(elts) % rows
@@ -209,7 +197,9 @@ def colify(elts, **options):
output.write(" " * indent)
for col in xrange(cols):
elt = col * rows + row
- output.write(formats[col] % elts[elt])
+ width = config.widths[col] + cextra(elts[elt])
+ fmt = '%%-%ds' % width
+ output.write(fmt % elts[elt])
output.write("\n")
row += 1