Fix set-colors unable to set tab_bar_background to none

This commit is contained in:
Kovid Goyal
2021-10-25 10:01:32 +05:30
parent 23d0db5458
commit 63e23d7fe3
7 changed files with 63 additions and 57 deletions

View File

@@ -3,7 +3,7 @@
import os
from typing import TYPE_CHECKING, Dict, Iterable, Optional, Tuple, Union
from typing import TYPE_CHECKING, Dict, Iterable, Optional
from kitty.config import parse_config
from kitty.fast_data_types import patch_color_profiles
@@ -18,24 +18,29 @@ if TYPE_CHECKING:
from kitty.cli_stub import SetColorsRCOptions as CLIOptions
def parse_colors(args: Iterable[str]) -> Tuple[Dict[str, int], Optional[Union[int, bool]]]:
def parse_colors(args: Iterable[str]) -> Dict[str, Optional[int]]:
colors: Dict[str, Optional[Color]] = {}
nullable_colors: Dict[str, Optional[int]] = {}
for spec in args:
if '=' in spec:
colors.update(parse_config((spec.replace('=', ' '),)))
else:
with open(os.path.expanduser(spec), encoding='utf-8', errors='replace') as f:
colors.update(parse_config(f))
q = colors.pop('cursor_text_color', False)
ctc = int(q) if isinstance(q, Color) else (False if q is False else None)
return {k: int(v) for k, v in colors.items() if isinstance(v, Color)}, ctc
for k in ('cursor_text_color', 'tab_bar_background'):
q = colors.pop(k, False)
if q is not False:
val = int(q) if isinstance(q, Color) else None
nullable_colors[k] = val
ans: Dict[str, Optional[int]] = {k: int(v) for k, v in colors.items() if isinstance(v, Color)}
ans.update(nullable_colors)
return ans
class SetColors(RemoteCommand):
'''
colors+: An object mapping names to colors as 24-bit RGB integers
cursor_text_color: A 24-bit color for text under the cursor, or null to use background.
colors+: An object mapping names to colors as 24-bit RGB integers or null for nullable colors
match_window: Window to change colors in
match_tab: Tab to change colors in
all: Boolean indicating change colors everywhere or not
@@ -72,35 +77,28 @@ this option, any color arguments are ignored and --configured and --all are impl
args_completion = {'files': ('CONF files', ('*.conf',))}
def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: ArgsType) -> PayloadType:
final_colors: Dict[str, int] = {}
cursor_text_color: Optional[Union[int, bool]] = False
final_colors: Dict[str, Optional[int]] = {}
if not opts.reset:
try:
final_colors, cursor_text_color = parse_colors(args)
final_colors = parse_colors(args)
except Exception as err:
raise ParsingOfArgsFailed(str(err)) from err
ans = {
'match_window': opts.match, 'match_tab': opts.match_tab,
'all': opts.all or opts.reset, 'configured': opts.configured or opts.reset,
'colors': final_colors, 'reset': opts.reset, 'dummy': 0
'colors': final_colors, 'reset': opts.reset,
}
if cursor_text_color is not False:
ans['cursor_text_color'] = cursor_text_color
del ans['dummy']
return ans
def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:
windows = self.windows_for_payload(boss, window, payload_get)
colors = payload_get('colors')
cursor_text_color = payload_get('cursor_text_color', missing=False)
colors: Dict[str, Optional[int]] = payload_get('colors')
if payload_get('reset'):
colors = {k: int(v) for k, v in boss.startup_colors.items()}
cursor_text_color = boss.startup_cursor_text_color
colors['cursor_text_color'] = None if boss.startup_cursor_text_color is None else int(boss.startup_cursor_text_color)
profiles = tuple(w.screen.color_profile for w in windows)
if isinstance(cursor_text_color, (tuple, list, Color)):
cursor_text_color = int(Color(*cursor_text_color))
patch_color_profiles(colors, cursor_text_color, profiles, payload_get('configured'))
boss.patch_colors(colors, cursor_text_color, payload_get('configured'))
patch_color_profiles(colors, profiles, payload_get('configured'))
boss.patch_colors(colors, payload_get('configured'))
default_bg_changed = 'background' in colors
for w in windows:
if default_bg_changed: