mesonconf: reorder output columns
mesonconf prints build dir information in the order of 'Option' 'Description' 'Current Value' and, optionally, 'Possible Value'. The Description tends to be longer and push the following values far right, sometimes way far than fits in the full screen size of a terminal on a FullHD monitor. Experienced users know which options they want to change without looking at the description string however they need to check the current values for sure. This patch moves the description to the last column. Now mesonconf prints options in the following order: 'Option' 'Current Value' 'Possible Value' 'Description' To implement this, mainly print_aligned() is modified. The second argument of the function is changed from - array of array of string to - array of dict with 'name', 'descr', 'value', and 'choices, which maps to 'option', 'description', 'current value' and 'possible values', respectively. Since the position of the possible values are moved before its description, the presence and the length of it affects header as well as the following description. Thus, we cal curate it before printing the header. To avoid re-calculation, we keep string version of the values and flattened version of the possible values _in the given array_, which means that now the print_aligned() function modify the the given array. The current callers do not use the passing array. So there should be no bad effects.
This commit is contained in:
parent
a3856be1d5
commit
abd12b69ea
|
@ -58,37 +58,62 @@ class Conf:
|
||||||
def print_aligned(self, arr):
|
def print_aligned(self, arr):
|
||||||
if not arr:
|
if not arr:
|
||||||
return
|
return
|
||||||
titles = ['Option', 'Description', 'Current Value', '']
|
titles = {'name': 'Option', 'descr': 'Description', 'value': 'Current Value', 'choices': 'Possible Values'}
|
||||||
longest_name = len(titles[0])
|
len_name = longest_name = len(titles['name'])
|
||||||
longest_descr = len(titles[1])
|
len_descr = longest_descr = len(titles['descr'])
|
||||||
longest_value = len(titles[2])
|
len_value = longest_value = len(titles['value'])
|
||||||
longest_possible_value = len(titles[3])
|
len_choices = longest_choices = 0 # not printed if we don't get any optional values
|
||||||
for x in arr:
|
|
||||||
longest_name = max(longest_name, len(x[0]))
|
|
||||||
longest_descr = max(longest_descr, len(x[1]))
|
|
||||||
longest_value = max(longest_value, len(str(x[2])))
|
|
||||||
if x[3]:
|
|
||||||
longest_possible_value = max(longest_possible_value, len(x[3]))
|
|
||||||
|
|
||||||
if longest_possible_value > 0:
|
# calculate the max length of each
|
||||||
titles[3] = 'Possible Values'
|
for x in arr:
|
||||||
print(' %s%s %s%s %s%s %s' % (titles[0], ' ' * (longest_name - len(titles[0])), titles[1], ' ' * (longest_descr - len(titles[1])), titles[2], ' ' * (longest_value - len(titles[2])), titles[3]))
|
name = x['name']
|
||||||
print(' %s%s %s%s %s%s %s' % ('-' * len(titles[0]), ' ' * (longest_name - len(titles[0])), '-' * len(titles[1]), ' ' * (longest_descr - len(titles[1])), '-' * len(titles[2]), ' ' * (longest_value - len(titles[2])), '-' * len(titles[3])))
|
descr = x['descr']
|
||||||
|
value = x['value'] if isinstance(x['value'], str) else str(x['value']).lower()
|
||||||
|
choices = ''
|
||||||
|
if isinstance(x['choices'], list):
|
||||||
|
if x['choices']:
|
||||||
|
x['choices'] = [s if isinstance(s, str) else str(s).lower() for s in x['choices']]
|
||||||
|
choices = '[%s]' % ', '.join(map(str, x['choices']))
|
||||||
|
elif x['choices']:
|
||||||
|
choices = x['choices'] if isinstance(x['choices'], str) else str(x['choices']).lower()
|
||||||
|
|
||||||
|
longest_name = max(longest_name, len(name))
|
||||||
|
longest_descr = max(longest_descr, len(descr))
|
||||||
|
longest_value = max(longest_value, len(value))
|
||||||
|
longest_choices = max(longest_choices, len(choices))
|
||||||
|
|
||||||
|
# update possible non strings
|
||||||
|
x['value'] = value
|
||||||
|
x['choices'] = choices
|
||||||
|
|
||||||
|
# prints header
|
||||||
|
namepad = ' ' * (longest_name - len_name)
|
||||||
|
valuepad = ' ' * (longest_value - len_value)
|
||||||
|
if longest_choices:
|
||||||
|
len_choices = len(titles['choices'])
|
||||||
|
longest_choices = max(longest_choices, len_choices)
|
||||||
|
choicepad = ' ' * (longest_choices - len_choices)
|
||||||
|
print(' %s%s %s%s %s%s %s' % (titles['name'], namepad, titles['value'], valuepad, titles['choices'], choicepad, titles['descr']))
|
||||||
|
print(' %s%s %s%s %s%s %s' % ('-' * len_name, namepad, '-' * len_value, valuepad, '-' * len_choices, choicepad, '-' * len_descr))
|
||||||
|
else:
|
||||||
|
print(' %s%s %s%s %s' % (titles['name'], namepad, titles['value'], valuepad, titles['descr']))
|
||||||
|
print(' %s%s %s%s %s' % ('-' * len_name, namepad, '-' * len_value, valuepad, '-' * len_descr))
|
||||||
|
|
||||||
|
# print values
|
||||||
for i in arr:
|
for i in arr:
|
||||||
name = i[0]
|
name = i['name']
|
||||||
descr = i[1]
|
descr = i['descr']
|
||||||
value = i[2] if isinstance(i[2], str) else str(i[2]).lower()
|
value = i['value']
|
||||||
possible_values = ''
|
choices = i['choices']
|
||||||
if isinstance(i[3], list):
|
|
||||||
if len(i[3]) > 0:
|
|
||||||
i[3] = [s if isinstance(s, str) else str(s).lower() for s in i[3]]
|
|
||||||
possible_values = '[%s]' % ', '.join(map(str, i[3]))
|
|
||||||
elif i[3]:
|
|
||||||
possible_values = i[3] if isinstance(i[3], str) else str(i[3]).lower()
|
|
||||||
namepad = ' ' * (longest_name - len(name))
|
namepad = ' ' * (longest_name - len(name))
|
||||||
descrpad = ' ' * (longest_descr - len(descr))
|
valuepad = ' ' * (longest_value - len(value))
|
||||||
valuepad = ' ' * (longest_value - len(str(value)))
|
if longest_choices:
|
||||||
f = ' %s%s %s%s %s%s %s' % (name, namepad, descr, descrpad, value, valuepad, possible_values)
|
choicespad = ' ' * (longest_choices - len(choices))
|
||||||
|
f = ' %s%s %s%s %s%s %s' % (name, namepad, value, valuepad, choices, choicespad, descr)
|
||||||
|
else:
|
||||||
|
f = ' %s%s %s%s %s' % (name, namepad, value, valuepad, descr)
|
||||||
|
|
||||||
print(f)
|
print(f)
|
||||||
|
|
||||||
def set_options(self, options):
|
def set_options(self, options):
|
||||||
|
@ -133,8 +158,10 @@ class Conf:
|
||||||
print('Core options:')
|
print('Core options:')
|
||||||
carr = []
|
carr = []
|
||||||
for key in ['buildtype', 'warning_level', 'werror', 'strip', 'unity', 'default_library']:
|
for key in ['buildtype', 'warning_level', 'werror', 'strip', 'unity', 'default_library']:
|
||||||
carr.append([key, coredata.get_builtin_option_description(key),
|
carr.append({'name': key,
|
||||||
self.coredata.get_builtin_option(key), coredata.get_builtin_option_choices(key)])
|
'descr': coredata.get_builtin_option_description(key),
|
||||||
|
'value': self.coredata.get_builtin_option(key),
|
||||||
|
'choices': coredata.get_builtin_option_choices(key)})
|
||||||
self.print_aligned(carr)
|
self.print_aligned(carr)
|
||||||
print('')
|
print('')
|
||||||
print('Base options:')
|
print('Base options:')
|
||||||
|
@ -145,7 +172,7 @@ class Conf:
|
||||||
coarr = []
|
coarr = []
|
||||||
for k in okeys:
|
for k in okeys:
|
||||||
o = self.coredata.base_options[k]
|
o = self.coredata.base_options[k]
|
||||||
coarr.append([k, o.description, o.value, ''])
|
coarr.append({'name': k, 'descr': o.description, 'value': o.value, 'choices': ''})
|
||||||
self.print_aligned(coarr)
|
self.print_aligned(coarr)
|
||||||
print('')
|
print('')
|
||||||
print('Compiler arguments:')
|
print('Compiler arguments:')
|
||||||
|
@ -164,7 +191,7 @@ class Conf:
|
||||||
coarr = []
|
coarr = []
|
||||||
for k in okeys:
|
for k in okeys:
|
||||||
o = self.coredata.compiler_options[k]
|
o = self.coredata.compiler_options[k]
|
||||||
coarr.append([k, o.description, o.value, ''])
|
coarr.append({'name': k, 'descr': o.description, 'value': o.value, 'choices': ''})
|
||||||
self.print_aligned(coarr)
|
self.print_aligned(coarr)
|
||||||
print('')
|
print('')
|
||||||
print('Directories:')
|
print('Directories:')
|
||||||
|
@ -183,8 +210,10 @@ class Conf:
|
||||||
'localstatedir',
|
'localstatedir',
|
||||||
'sharedstatedir',
|
'sharedstatedir',
|
||||||
]:
|
]:
|
||||||
parr.append([key, coredata.get_builtin_option_description(key),
|
parr.append({'name': key,
|
||||||
self.coredata.get_builtin_option(key), coredata.get_builtin_option_choices(key)])
|
'descr': coredata.get_builtin_option_description(key),
|
||||||
|
'value': self.coredata.get_builtin_option(key),
|
||||||
|
'choices': coredata.get_builtin_option_choices(key)})
|
||||||
self.print_aligned(parr)
|
self.print_aligned(parr)
|
||||||
print('')
|
print('')
|
||||||
print('Project options:')
|
print('Project options:')
|
||||||
|
@ -203,14 +232,19 @@ class Conf:
|
||||||
else:
|
else:
|
||||||
# A non zero length list or string, convert to string
|
# A non zero length list or string, convert to string
|
||||||
choices = str(opt.choices)
|
choices = str(opt.choices)
|
||||||
optarr.append([key, opt.description, opt.value, choices])
|
optarr.append({'name': key,
|
||||||
|
'descr': opt.description,
|
||||||
|
'value': opt.value,
|
||||||
|
'choices': choices})
|
||||||
self.print_aligned(optarr)
|
self.print_aligned(optarr)
|
||||||
print('')
|
print('')
|
||||||
print('Testing options:')
|
print('Testing options:')
|
||||||
tarr = []
|
tarr = []
|
||||||
for key in ['stdsplit', 'errorlogs']:
|
for key in ['stdsplit', 'errorlogs']:
|
||||||
tarr.append([key, coredata.get_builtin_option_description(key),
|
tarr.append({'name': key,
|
||||||
self.coredata.get_builtin_option(key), coredata.get_builtin_option_choices(key)])
|
'descr': coredata.get_builtin_option_description(key),
|
||||||
|
'value': self.coredata.get_builtin_option(key),
|
||||||
|
'choices': coredata.get_builtin_option_choices(key)})
|
||||||
self.print_aligned(tarr)
|
self.print_aligned(tarr)
|
||||||
|
|
||||||
def run(args):
|
def run(args):
|
||||||
|
|
Loading…
Reference in New Issue