diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2020-04-23 12:14:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-23 12:14:40 -0700 |
commit | 0c0f11caf681cf8e1405c8579b5dffaec16d360a (patch) | |
tree | 09b468e391b8ac1c4e0902fe43c7ad2df0a12e42 | |
parent | 686f0e21de510a12ee3d6af410448eb405d3e7b6 (diff) | |
download | spack-0c0f11caf681cf8e1405c8579b5dffaec16d360a.tar.gz spack-0c0f11caf681cf8e1405c8579b5dffaec16d360a.tar.bz2 spack-0c0f11caf681cf8e1405c8579b5dffaec16d360a.tar.xz spack-0c0f11caf681cf8e1405c8579b5dffaec16d360a.zip |
spack info: allow variants section to be as wide as the terminal (#16254)
The variants table in `spack info` is cramped, as the *widest* it can be
is 80 columns. And that's actually only sort of true -- the padding
calculation is off, so it still wraps on terminals of size 80 because it
comes out *slightly* wider.
This change looks at the terminal size and calculates the width of the
description column based on it. On larger terminals, the output looks
much nicer, and on small terminals, the output no longer wraps.
Here's an example for `spack info qmcpack` with 110 columns.
Before:
Name [Default] Allowed values Description
==================== ==================== ==============================
afqmc [off] on, off Install with AFQMC support.
NOTE that if used in
combination with CUDA, only
AFQMC will have CUDA.
build_type [Release] Debug, Release, The build type to build
RelWithDebInfo
complex [off] on, off Build the complex (general
twist/k-point) version
cuda [off] on, off Build with CUDA
After:
Name [Default] Allowed values Description
==================== ==================== ========================================================
afqmc [off] on, off Install with AFQMC support. NOTE that if used in
combination with CUDA, only AFQMC will have CUDA.
build_type [Release] Debug, Release, The build type to build
RelWithDebInfo
complex [off] on, off Build the complex (general twist/k-point) version
cuda [off] on, off Build with CUDA
-rw-r--r-- | lib/spack/spack/cmd/info.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/spack/spack/cmd/info.py b/lib/spack/spack/cmd/info.py index f8db9e10cb..fa674317ab 100644 --- a/lib/spack/spack/cmd/info.py +++ b/lib/spack/spack/cmd/info.py @@ -8,6 +8,7 @@ from __future__ import print_function import textwrap from six.moves import zip_longest +import llnl.util.tty as tty import llnl.util.tty.color as color from llnl.util.tty.colify import colify @@ -53,11 +54,9 @@ def variant(s): class VariantFormatter(object): - def __init__(self, variants, max_widths=(30, 20, 30)): + def __init__(self, variants): self.variants = variants self.headers = ('Name [Default]', 'Allowed values', 'Description') - # Set max headers lengths - self.max_column_widths = max_widths # Formats fmt_name = '{0} [{1}]' @@ -67,7 +66,7 @@ class VariantFormatter(object): # than that self.column_widths = [len(x) for x in self.headers] - # Update according to line lengths + # Expand columns based on max line lengths for k, v in variants.items(): candidate_max_widths = ( len(fmt_name.format(k, self.default(v))), # Name [Default] @@ -81,12 +80,18 @@ class VariantFormatter(object): max(self.column_widths[2], candidate_max_widths[2]) ) - # Reduce to at most the maximum allowed - self.column_widths = ( - min(self.column_widths[0], self.max_column_widths[0]), - min(self.column_widths[1], self.max_column_widths[1]), - min(self.column_widths[2], self.max_column_widths[2]) + # Don't let name or possible values be less than max widths + _, cols = tty.terminal_size() + max_name = min(self.column_widths[0], 30) + max_vals = min(self.column_widths[1], 20) + + # allow the description column to extend as wide as the terminal. + max_description = min( + self.column_widths[2], + # min width 70 cols, 14 cols of margins and column spacing + max(cols, 70) - max_name - max_vals - 14, ) + self.column_widths = (max_name, max_vals, max_description) # Compute the format self.fmt = "%%-%ss%%-%ss%%s" % ( |