Keep the list of nullable colors up to date automatically

This commit is contained in:
Kovid Goyal 2021-10-28 15:21:42 +05:30
parent 4839cbe9d0
commit 1251f9ec80
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 25 additions and 2 deletions

View File

@ -3,12 +3,28 @@
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
import re
from kitty.conf.generate import write_output
def main() -> None:
from kitty.options.definition import definition
write_output('kitty', definition)
nullable_colors = []
for opt in definition.iter_all_options():
if callable(opt.parser_func) and opt.parser_func.__name__ in ('to_color_or_none', 'cursor_text_color'):
nullable_colors.append(opt.name)
with open('kitty/rc/set_colors.py', 'r+') as f:
raw = f.read()
nraw = re.sub(
r'(# NULLABLE_COLORS_START).+?(\s+# NULLABLE_COLORS_END)',
r'\1' + '\n ' + '\n '.join(map(lambda x: f'{x!r},', sorted(nullable_colors))) + r'\2',
raw, flags=re.DOTALL | re.MULTILINE)
if nraw != raw:
f.seek(0)
f.truncate()
f.write(nraw)
from kittens.diff.options.definition import definition as kd
write_output('kittens.diff', kd)

View File

@ -18,8 +18,15 @@ if TYPE_CHECKING:
nullable_colors = (
'cursor', 'cursor_text_color', 'tab_bar_background', 'tab_bar_margin_color',
'selection_foreground', 'selection_background', 'active_border_color'
# NULLABLE_COLORS_START
'active_border_color',
'cursor',
'cursor_text_color',
'selection_background',
'selection_foreground',
'tab_bar_background',
'tab_bar_margin_color',
# NULLABLE_COLORS_END
)