summary: Wrap lines when printing lists

When a list_sep is provided (e.g. ', ') all items are printed on the
same line, which gets ugly on very long lists (e.g. list of plugins
enabled).
pull/7472/head
Xavier Claessens 5 years ago committed by Nirbheek Chauhan
parent 8f106a2b9a
commit 7f1e9b7492
  1. 34
      mesonbuild/interpreter.py
  2. 4
      run_unittests.py
  3. 1
      test cases/unit/73 summary/meson.build

@ -1844,10 +1844,18 @@ class Summary:
if bool_yn and isinstance(i, bool):
formatted_values.append(mlog.green('YES') if i else mlog.red('NO'))
else:
formatted_values.append(i)
formatted_values.append(str(i))
self.sections[section][k] = (formatted_values, list_sep)
self.max_key_len = max(self.max_key_len, len(k))
def text_len(self, v):
if isinstance(v, str):
return len(v)
elif isinstance(v, mlog.AnsiDecorator):
return len(v.text)
else:
raise RuntimeError('Expecting only strings or AnsiDecorator')
def dump(self):
mlog.log(self.project_name, mlog.normal_cyan(self.project_version))
for section, values in self.sections.items():
@ -1859,12 +1867,28 @@ class Summary:
indent = self.max_key_len - len(k) + 3
end = ' ' if v else ''
mlog.log(' ' * indent, k + ':', end=end)
if list_sep is None:
indent = self.max_key_len + 6
list_sep = '\n' + ' ' * indent
mlog.log(*v, sep=list_sep)
indent = self.max_key_len + 6
self.dump_value(v, list_sep, indent)
mlog.log('') # newline
def dump_value(self, arr, list_sep, indent):
lines_sep = '\n' + ' ' * indent
if list_sep is None:
mlog.log(*arr, sep=lines_sep)
return
max_len = shutil.get_terminal_size().columns
line = []
line_len = indent
lines_sep = list_sep.rstrip() + lines_sep
for v in arr:
v_len = self.text_len(v) + len(list_sep)
if line and line_len + v_len > max_len:
mlog.log(*line, sep=list_sep, end=lines_sep)
line_len = indent
line = []
line.append(v)
line_len += v_len
mlog.log(*line, sep=list_sep)
class MesonMain(InterpreterObject):
def __init__(self, build, interpreter):

@ -4635,6 +4635,10 @@ recommended as it is not supported on some platforms''')
no: NO
coma list: a, b, c
Plugins
long coma list: alpha, alphacolor, apetag, audiofx, audioparsers, auparse,
autodetect, avi
Subprojects
sub: YES
sub2: NO Problem encountered: This subproject failed

@ -13,3 +13,4 @@ summary('A number', 1, section: 'Configuration')
summary('yes', true, bool_yn : true, section: 'Configuration')
summary('no', false, bool_yn : true, section: 'Configuration')
summary('coma list', ['a', 'b', 'c'], list_sep: ', ', section: 'Configuration')
summary('long coma list', ['alpha', 'alphacolor', 'apetag', 'audiofx', 'audioparsers', 'auparse', 'autodetect', 'avi'], list_sep: ', ', section: 'Plugins')

Loading…
Cancel
Save