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

View File

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