From 0045244295ba766f0ee092dca1adcd3bd04bc652 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 31 Jul 2021 18:44:39 +0530 Subject: [PATCH] All option instances must not share the same color table --- kitty/conf/generate.py | 2 ++ kitty/debug_config.py | 14 ++++++++++++-- kitty/options/types.py | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/kitty/conf/generate.py b/kitty/conf/generate.py index 587c4b00d..f1e47e938 100644 --- a/kitty/conf/generate.py +++ b/kitty/conf/generate.py @@ -182,6 +182,8 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]: a(' config_overrides: typing.Tuple[str, ...] = ()') a('') a(' def __init__(self, options_dict: typing.Optional[typing.Dict[str, typing.Any]] = None) -> None:') + if defn.has_color_table: + a(' self.color_table = array(self.color_table.typecode, self.color_table)') a(' if options_dict is not None:') a(' for key in option_names:') a(' setattr(self, key, options_dict[key])') diff --git a/kitty/debug_config.py b/kitty/debug_config.py index 002cdf0e0..fe7b9c857 100644 --- a/kitty/debug_config.py +++ b/kitty/debug_config.py @@ -7,12 +7,14 @@ from functools import partial from pprint import pformat from typing import Callable, Dict, Generator, Iterable, Set, Tuple +from kittens.tui.operations import colored, styled + from .cli import version from .conf.utils import KeyAction from .constants import is_macos, is_wayland -from kittens.tui.operations import colored from .options.types import Options as KittyOpts, defaults from .options.utils import MouseMap +from .rgb import Color, color_as_sharp from .types import MouseEvent, SingleKey from .typing import SequenceMap @@ -113,6 +115,7 @@ def compare_opts(opts: KittyOpts, print: Callable) -> None: ] field_len = max(map(len, changed_opts)) if changed_opts else 20 fmt = '{{:{:d}s}}'.format(field_len) + colors = [] for f in changed_opts: val = getattr(opts, f) if isinstance(val, dict): @@ -123,7 +126,11 @@ def compare_opts(opts: KittyOpts, print: Callable) -> None: else: print(pformat(val)) else: - print(title(fmt.format(f)), str(getattr(opts, f))) + val = getattr(opts, f) + if isinstance(val, Color): + colors.append(fmt.format(f) + ' ' + color_as_sharp(val) + ' ' + styled(' ', bg=val)) + else: + print(fmt.format(f), str(getattr(opts, f))) compare_mousemaps(opts.mousemap, default_opts.mousemap, print) final_, initial_ = opts.keymap, default_opts.keymap @@ -133,6 +140,9 @@ def compare_opts(opts: KittyOpts, print: Callable) -> None: final.update(final_s) initial.update(initial_s) compare_keymaps(final, initial, print) + if colors: + print(f'{title("Colors")}:', end='\n\t') + print('\n\t'.join(sorted(colors))) def debug_config(opts: KittyOpts) -> str: diff --git a/kitty/options/types.py b/kitty/options/types.py index 9555c1f69..87560f785 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -606,6 +606,7 @@ class Options: config_overrides: typing.Tuple[str, ...] = () def __init__(self, options_dict: typing.Optional[typing.Dict[str, typing.Any]] = None) -> None: + self.color_table = array(self.color_table.typecode, self.color_table) if options_dict is not None: for key in option_names: setattr(self, key, options_dict[key])