@@ -57,7 +57,7 @@ def variant(s):
5757class VariantFormatter (object ):
5858 def __init__ (self , variants ):
5959 self .variants = variants
60- self .headers = ('Name [Default]' , 'Allowed values' , 'Description' )
60+ self .headers = ('Name [Default]' , 'When' , ' Allowed values' , 'Description' )
6161
6262 # Formats
6363 fmt_name = '{0} [{1}]'
@@ -68,36 +68,41 @@ def __init__(self, variants):
6868 self .column_widths = [len (x ) for x in self .headers ]
6969
7070 # Expand columns based on max line lengths
71- for k , v in variants .items ():
71+ for k , e in variants .items ():
72+ v , w = e
7273 candidate_max_widths = (
7374 len (fmt_name .format (k , self .default (v ))), # Name [Default]
75+ len (str (w )),
7476 len (v .allowed_values ), # Allowed values
7577 len (v .description ) # Description
7678 )
7779
7880 self .column_widths = (
7981 max (self .column_widths [0 ], candidate_max_widths [0 ]),
8082 max (self .column_widths [1 ], candidate_max_widths [1 ]),
81- max (self .column_widths [2 ], candidate_max_widths [2 ])
83+ max (self .column_widths [2 ], candidate_max_widths [2 ]),
84+ max (self .column_widths [3 ], candidate_max_widths [3 ])
8285 )
8386
8487 # Don't let name or possible values be less than max widths
8588 _ , cols = tty .terminal_size ()
8689 max_name = min (self .column_widths [0 ], 30 )
87- max_vals = min (self .column_widths [1 ], 20 )
90+ max_when = min (self .column_widths [1 ], 30 )
91+ max_vals = min (self .column_widths [2 ], 20 )
8892
8993 # allow the description column to extend as wide as the terminal.
9094 max_description = min (
91- self .column_widths [2 ],
95+ self .column_widths [3 ],
9296 # min width 70 cols, 14 cols of margins and column spacing
9397 max (cols , 70 ) - max_name - max_vals - 14 ,
9498 )
95- self .column_widths = (max_name , max_vals , max_description )
99+ self .column_widths = (max_name , max_when , max_vals , max_description )
96100
97101 # Compute the format
98- self .fmt = "%%-%ss%%-%ss%%s" % (
102+ self .fmt = "%%-%ss%%-%ss%%-%ss%% s" % (
99103 self .column_widths [0 ] + 4 ,
100- self .column_widths [1 ] + 4
104+ self .column_widths [1 ] + 4 ,
105+ self .column_widths [2 ] + 4
101106 )
102107
103108 def default (self , v ):
@@ -115,21 +120,27 @@ def lines(self):
115120 underline = tuple ([w * "=" for w in self .column_widths ])
116121 yield ' ' + self .fmt % underline
117122 yield ''
118- for k , v in sorted (self .variants .items ()):
123+ for k , e in sorted (self .variants .items ()):
124+ v , w = e
119125 name = textwrap .wrap (
120126 '{0} [{1}]' .format (k , self .default (v )),
121127 width = self .column_widths [0 ]
122128 )
129+ if len (w ) == 1 :
130+ w = w [0 ]
131+ if w == spack .spec .Spec ():
132+ w = '--'
133+ when = textwrap .wrap (str (w ), width = self .column_widths [1 ])
123134 allowed = v .allowed_values .replace ('True, False' , 'on, off' )
124- allowed = textwrap .wrap (allowed , width = self .column_widths [1 ])
135+ allowed = textwrap .wrap (allowed , width = self .column_widths [2 ])
125136 description = []
126137 for d_line in v .description .split ('\n ' ):
127138 description += textwrap .wrap (
128139 d_line ,
129- width = self .column_widths [2 ]
140+ width = self .column_widths [3 ]
130141 )
131142 for t in zip_longest (
132- name , allowed , description , fillvalue = ''
143+ name , when , allowed , description , fillvalue = ''
133144 ):
134145 yield " " + self .fmt % t
135146
@@ -232,7 +243,7 @@ def print_text_info(pkg):
232243
233244 formatter = VariantFormatter (pkg .variants )
234245 for line in formatter .lines :
235- color .cprint (line )
246+ color .cprint (color . cescape ( line ) )
236247
237248 if hasattr (pkg , 'phases' ) and pkg .phases :
238249 color .cprint ('' )
0 commit comments