Fix the generated sample kitty.conf containing invalid options

This commit is contained in:
pagedown 2022-04-30 02:23:33 +08:00
parent 4a7125ec92
commit 76f84e32c4
No known key found for this signature in database
GPG key ID: E921CF18AC8FF6EB

View file

@ -289,7 +289,11 @@ def as_conf(self, commented: bool = False, level: int = 0) -> List[str]:
for k in self.items:
if k.documented:
documented = True
a(f'{self.name} {k.defval_as_str if k.add_to_default else ""}'.rstrip())
if k.add_to_default:
a(f'{self.name} {k.defval_as_str}'.rstrip())
else:
# Comment out multi-options that have no default values
a(f'# {self.name}'.rstrip())
if not k.add_to_default and k.defval_as_str:
a('')
a(f'#: E.g. {self.name} {k.defval_as_str}'.rstrip())
@ -565,6 +569,9 @@ def as_conf(self, commented: bool = False, level: int = 0) -> List[str]:
if commented:
ans = [x if x.startswith('#') or not x.strip() else (f'# {x}') for x in ans]
else:
# Comment out any invalid options that have no value
ans = [f'# {x}' if not x.startswith('#') and len(x.strip().split()) == 1 else x for x in ans]
return ans