Only parse color options for key=val specs in parse_colors

This commit is contained in:
Kovid Goyal 2026-04-26 10:15:28 +05:30
parent 54d94d93b0
commit 2ead0de844
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 314 additions and 7 deletions

View file

@ -60,9 +60,11 @@ def main(args: list[str]=sys.argv) -> None:
patch_color_list('tools/themes/collection.go', all_colors, 'ALL') patch_color_list('tools/themes/collection.go', all_colors, 'ALL')
nc = ',\n '.join(f'{x!r}' for x in nullable_colors) nc = ',\n '.join(f'{x!r}' for x in nullable_colors)
sc = ',\n '.join(f'{x!r}' for x in special_colors) sc = ',\n '.join(f'{x!r}' for x in special_colors)
ac = ',\n '.join(f'{x!r}' for x in all_colors)
write_output('kitty', definition, write_output('kitty', definition,
f'\nnullable_colors = frozenset({{\n {nc}\n}})\n' f'\nnullable_colors = frozenset({{\n {nc}\n}})\n'
f'\nspecial_colors = frozenset({{\n {sc}\n}})\n' f'\nspecial_colors = frozenset({{\n {sc}\n}})\n'
f'\nall_colors = frozenset({{\n {ac}\n}})\n'
) )

View file

@ -5,13 +5,14 @@
from collections.abc import Iterable, Sequence from collections.abc import Iterable, Sequence
from contextlib import suppress from contextlib import suppress
from enum import Enum from enum import Enum
from typing import Literal, Optional, TypedDict from typing import Any, Literal, Optional, TypedDict
from .config import parse_config from .config import parse_config
from .constants import config_dir from .constants import config_dir
from .fast_data_types import Color, get_boss, get_options, glfw_get_system_color_theme, patch_color_profiles, patch_global_colors, set_os_window_chrome from .fast_data_types import Color, get_boss, get_options, glfw_get_system_color_theme, patch_color_profiles, patch_global_colors, set_os_window_chrome
from .options.types import Options, nullable_colors, special_colors from .options.types import Options, all_colors, nullable_colors, special_colors
from .rgb import color_from_int from .rgb import color_from_int
from .types import run_once
from .typing_compat import WindowType from .typing_compat import WindowType
ColorsSpec = dict[str, Optional[int]] ColorsSpec = dict[str, Optional[int]]
@ -191,19 +192,32 @@ def apply_theme(self, new_value: ColorSchemes, notify_on_bg_change: bool = True)
theme_colors = ThemeColors() theme_colors = ThemeColors()
def parse_colors(args: Iterable[str | Iterable[str]], background_image_options: BackgroundImageOptions | None = None) -> Colors: @run_once
def all_color_related_conf_keys() -> frozenset[str]:
return all_colors | frozenset(BackgroundImageOptions.__optional_keys__) | frozenset({'transparent_background_colors'})
def parse_colors(
args: Iterable[str | Iterable[str]], background_image_options: BackgroundImageOptions | None = None,
allow_reading_conf_files: bool = True,
) -> Colors:
from kitty.options.parse import parse_conf_item
colors: dict[str, Color | None | int] = {} colors: dict[str, Color | None | int] = {}
nullable_color_map: dict[str, int | None] = {} nullable_color_map: dict[str, int | None] = {}
special_color_map: dict[str, int] = {} special_color_map: dict[str, int] = {}
transparent_background_colors = () transparent_background_colors = ()
allowed = all_color_related_conf_keys()
for spec in args: for spec in args:
conf: dict[str, Any] = {}
if isinstance(spec, str): if isinstance(spec, str):
if '=' in spec: k, sep, v = spec.partition('=')
conf = parse_config((spec.replace('=', ' '),)) if sep == '=':
else: if k in allowed:
parse_conf_item(k, v, conf)
elif allow_reading_conf_files:
with open(os.path.expanduser(spec), encoding='utf-8', errors='replace') as f: with open(os.path.expanduser(spec), encoding='utf-8', errors='replace') as f:
conf = parse_config(f) conf = parse_config(f)
else: elif allow_reading_conf_files:
conf = parse_config(spec) conf = parse_config(spec)
transparent_background_colors = conf.pop('transparent_background_colors', ()) transparent_background_colors = conf.pop('transparent_background_colors', ())
if background_image_options is not None: if background_image_options is not None:

291
kitty/options/types.py generated
View file

@ -1412,5 +1412,296 @@ def __setattr__(self, key: str, val: typing.Any) -> typing.Any:
'macos_titlebar_color' 'macos_titlebar_color'
}) })
all_colors = frozenset({
'cursor',
'cursor_text_color',
'cursor_trail_color',
'scrollbar_handle_color',
'scrollbar_track_color',
'url_color',
'visual_bell_color',
'active_border_color',
'inactive_border_color',
'bell_border_color',
'window_title_bar_active_foreground',
'window_title_bar_active_background',
'window_title_bar_inactive_foreground',
'window_title_bar_inactive_background',
'active_tab_foreground',
'active_tab_background',
'inactive_tab_foreground',
'inactive_tab_background',
'tab_bar_background',
'tab_bar_margin_color',
'foreground',
'background',
'selection_foreground',
'selection_background',
'color0',
'color8',
'color1',
'color9',
'color2',
'color10',
'color3',
'color11',
'color4',
'color12',
'color5',
'color13',
'color6',
'color14',
'color7',
'color15',
'mark1_foreground',
'mark1_background',
'mark2_foreground',
'mark2_background',
'mark3_foreground',
'mark3_background',
'color16',
'color17',
'color18',
'color19',
'color20',
'color21',
'color22',
'color23',
'color24',
'color25',
'color26',
'color27',
'color28',
'color29',
'color30',
'color31',
'color32',
'color33',
'color34',
'color35',
'color36',
'color37',
'color38',
'color39',
'color40',
'color41',
'color42',
'color43',
'color44',
'color45',
'color46',
'color47',
'color48',
'color49',
'color50',
'color51',
'color52',
'color53',
'color54',
'color55',
'color56',
'color57',
'color58',
'color59',
'color60',
'color61',
'color62',
'color63',
'color64',
'color65',
'color66',
'color67',
'color68',
'color69',
'color70',
'color71',
'color72',
'color73',
'color74',
'color75',
'color76',
'color77',
'color78',
'color79',
'color80',
'color81',
'color82',
'color83',
'color84',
'color85',
'color86',
'color87',
'color88',
'color89',
'color90',
'color91',
'color92',
'color93',
'color94',
'color95',
'color96',
'color97',
'color98',
'color99',
'color100',
'color101',
'color102',
'color103',
'color104',
'color105',
'color106',
'color107',
'color108',
'color109',
'color110',
'color111',
'color112',
'color113',
'color114',
'color115',
'color116',
'color117',
'color118',
'color119',
'color120',
'color121',
'color122',
'color123',
'color124',
'color125',
'color126',
'color127',
'color128',
'color129',
'color130',
'color131',
'color132',
'color133',
'color134',
'color135',
'color136',
'color137',
'color138',
'color139',
'color140',
'color141',
'color142',
'color143',
'color144',
'color145',
'color146',
'color147',
'color148',
'color149',
'color150',
'color151',
'color152',
'color153',
'color154',
'color155',
'color156',
'color157',
'color158',
'color159',
'color160',
'color161',
'color162',
'color163',
'color164',
'color165',
'color166',
'color167',
'color168',
'color169',
'color170',
'color171',
'color172',
'color173',
'color174',
'color175',
'color176',
'color177',
'color178',
'color179',
'color180',
'color181',
'color182',
'color183',
'color184',
'color185',
'color186',
'color187',
'color188',
'color189',
'color190',
'color191',
'color192',
'color193',
'color194',
'color195',
'color196',
'color197',
'color198',
'color199',
'color200',
'color201',
'color202',
'color203',
'color204',
'color205',
'color206',
'color207',
'color208',
'color209',
'color210',
'color211',
'color212',
'color213',
'color214',
'color215',
'color216',
'color217',
'color218',
'color219',
'color220',
'color221',
'color222',
'color223',
'color224',
'color225',
'color226',
'color227',
'color228',
'color229',
'color230',
'color231',
'color232',
'color233',
'color234',
'color235',
'color236',
'color237',
'color238',
'color239',
'color240',
'color241',
'color242',
'color243',
'color244',
'color245',
'color246',
'color247',
'color248',
'color249',
'color250',
'color251',
'color252',
'color253',
'color254',
'color255',
'wayland_titlebar_color',
'macos_titlebar_color'
})
secret_options = ('remote_control_password', 'file_transfer_confirmation_bypass') secret_options = ('remote_control_password', 'file_transfer_confirmation_bypass')