More string output improvements

This commit is contained in:
Florian Bruhin 2014-02-27 21:05:51 +01:00
parent 301f952ccb
commit 7d3e8d940c
2 changed files with 29 additions and 26 deletions

View File

@ -69,28 +69,26 @@ class NewConfig:
normal_wrapper = textwrap.TextWrapper(
width=72, replace_whitespace=False, break_long_words=False,
break_on_hyphens=False, initial_indent='# ',
subsequent_indent='# ')
subsequent_indent='# ', drop_whitespace=False)
option_wrapper = textwrap.TextWrapper(
width=72, replace_whitespace=False, break_long_words=False,
break_on_hyphens=False, initial_indent='# ',
break_on_hyphens=False, initial_indent='#' + ' ' * 5,
subsequent_indent='#' + ' ' * 5)
keyval_wrapper = textwrap.TextWrapper(
width=72, replace_whitespace=False, break_long_words=False,
break_on_hyphens=False, initial_indent='',
subsequent_indent=' ' * 4)
lines = []
for par in map(normal_wrapper.wrap,
configdata.FIRST_COMMENT.splitlines()):
lines += par
lines = configdata.FIRST_COMMENT.strip('\n').splitlines()
for secname, section in self.config.items():
lines.append('\n\n[{}]\n'.format(secname))
lines.append('\n[{}]'.format(secname))
seclines = configdata.SECTION_DESC[secname].splitlines()
for secline in seclines:
if 'http://' in secline:
lines.append('# ' + secline)
else:
lines += normal_wrapper.wrap(secline)
lines.append('')
if self.config[secname].descriptions:
lines.append('#')
for optname, option in section.items():
try:
desc = self.config[secname].descriptions[optname]
@ -98,11 +96,10 @@ class NewConfig:
continue
wrapped_desc = []
for descline in desc.splitlines():
if 'http://' in descline:
wrapped_desc.append('# ' + descline)
else:
wrapped_desc += option_wrapper.wrap(descline)
lines.append('\n'.join(wrapped_desc))
wrapped_desc += option_wrapper.wrap(descline)
lines.append('# {}:\n{}'.format(optname,
'\n'.join(wrapped_desc)))
for optname, option in section.items():
keyval = '{} = {}'.format(optname, option)
if 'http://' in keyval:
lines.append(keyval)

View File

@ -24,19 +24,25 @@ import qutebrowser.config.sections as sect
from qutebrowser.config.templates import SettingValue
FIRST_COMMENT = (
'vim: ft=dosini\n\n'
'Configfile for qutebrowser.\n\n'
"This configfile is parsed by python's configparser in extended "
'interpolation mode. The format is very INI-like, so there are '
'categories like [general] with "key = value"-pairs.\n\n'
"Note that you shouldn't add your own comments, as this file is "
'regenerated every time the config is saved.\n\n'
'Interpolation looks like ${value} or ${section:value} and will be '
'replaced by the respective value.\n\n'
'This is the default config, so if you want to remove anything from '
'here (as opposed to change/add), for example a keybinding, set it to '
'an empty value.')
FIRST_COMMENT = """
# vim: ft=dosini
#
# Configfile for qutebrowser.
#
# This configfile is parsed by python's configparser in extended
# interpolation mode. The format is very INI-like, so there are
# categories like [general] with "key = value"-pairs.
#
# Note that you shouldn't add your own comments, as this file is
# regenerated every time the config is saved.
#
# Interpolation looks like ${value} or ${section:value} and will be
# replaced by the respective value.
#
# This is the default config, so if you want to remove anything from
# here (as opposed to change/add), for example a keybinding, set it to
# an empty value.
"""
SECTION_DESC = {