diff --git a/kitty/boss.py b/kitty/boss.py index fd6499fab..0bbf4807d 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -26,6 +26,7 @@ from .fast_data_types import ( from .fonts.render import prerender, resize_fonts, set_font_family from .keys import get_shortcut, shortcut_matches from .remote_control import handle_cmd +from .rgb import Color, color_from_int from .session import create_session from .tabs import SpecialWindow, SpecialWindowInstance, TabManager from .utils import ( @@ -80,6 +81,7 @@ class Boss: def __init__(self, os_window_id, opts, args, cached_values): self.window_id_map = WeakValueDictionary() + self.startup_colors = {k: opts[k] for k in opts if isinstance(opts[k], Color)} self.pending_sequences = None self.cached_values = cached_values self.os_window_map = {} @@ -698,7 +700,6 @@ class Boss: tm.move_tab(-1) def patch_colors(self, spec, configured=False): - from .rgb import color_from_int if configured: for k, v in spec.items(): if hasattr(self.opts, k): diff --git a/kitty/config_utils.py b/kitty/config_utils.py index 1f7214a68..5bb0521a8 100644 --- a/kitty/config_utils.py +++ b/kitty/config_utils.py @@ -87,6 +87,20 @@ def create_options_class(keys): for k, v in kw.items(): setattr(self, k, v) + def __iter__(self): + return iter(keys) + + def __len__(self): + return len(keys) + + def __getitem__(self, i): + if isinstance(i, int): + i = keys[i] + try: + return getattr(self, i) + except AttributeError: + raise KeyError('No option named: {}'.format(i)) + def _asdict(self): return {k: getattr(self, k) for k in self._fields} @@ -95,7 +109,10 @@ def create_options_class(keys): ans.update(kw) return self.__class__(ans) - ans = type('Options', (), {'__slots__': slots, '__init__': __init__, '_asdict': _asdict, '_replace': _replace}) + ans = type('Options', (), { + '__slots__': slots, '__init__': __init__, '_asdict': _asdict, '_replace': _replace, '__iter__': __iter__, + '__len__': __len__, '__getitem__': __getitem__ + }) ans._fields = keys return ans diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 10a39ce18..61945cb48 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -485,26 +485,34 @@ cause colors to be changed in all windows. type=bool-set Also change the configured colors (i.e. the colors kitty will use for new windows or after a reset). + + +--reset +type=bool-set +Restore all colors to the values they has at kitty startup. Note that if you specify +this option, any color arguments are ignored and --configured and --all are implied. ''' + '\n\n' + MATCH_WINDOW_OPTION + '\n\n' + MATCH_TAB_OPTION.replace('--match -m', '--match-tab -t'), argspec='COLOR_OR_FILE ...' ) def cmd_set_colors(global_opts, opts, args): from .rgb import color_as_int, Color colors = {} - 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)) - colors = {k: color_as_int(v) for k, v in colors.items() if isinstance(v, Color)} + if not opts.reset: + 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)) + colors = {k: color_as_int(v) for k, v in colors.items() if isinstance(v, Color)} return { 'title': ' '.join(args), 'match_window': opts.match, 'match_tab': opts.match_tab, - 'all': opts.all, 'configured': opts.configured, 'colors': colors + 'all': opts.all or opts.reset, 'configured': opts.configured or opts.reset, 'colors': colors, 'reset': opts.reset } def set_colors(boss, window, payload): + from .rgb import color_as_int if payload['all']: windows = tuple(boss.all_windows) else: @@ -519,6 +527,8 @@ def set_colors(boss, window, payload): raise MatchError(payload['match_tab'], 'tabs') for tab in tabs: windows += tuple(tab) + if payload['reset']: + payload['colors'] = {k: color_as_int(v) for k, v in boss.startup_colors.items()} profiles = tuple(w.screen.color_profile for w in windows) from .fast_data_types import patch_color_profiles patch_color_profiles(payload['colors'], profiles, payload['configured'])