From d92f8a90ef6212be74c80ee7799f284550cf23a3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 21 Oct 2019 14:43:35 +0530 Subject: [PATCH] Allow changing colors by mapping a keyboard shortcut to read a kitty config file with color definitions. Fixes #2083 --- docs/changelog.rst | 4 ++++ docs/faq.rst | 9 +++++++-- kitty/boss.py | 6 ++++++ kitty/config.py | 9 +++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index a08881668..d9ca00abb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,6 +9,10 @@ To update |kitty|, :doc:`follow the instructions `. - Add a new style ``powerline`` for tab bar rendering, see :opt:`tab_bar_style` (:pull:`2021`) +- Allow changing colors by mapping a keyboard shortcut to read a kitty config + file with color definitions. See the :doc:`FAQ ` for details + (:iss:`2083`) + - Wayland: Fix key repeat not being stopped when focus leaves window. This is expected behavior on Wayland, apparently (:iss:`2014`) diff --git a/docs/faq.rst b/docs/faq.rst index 46050564b..8d7b20ee2 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -109,8 +109,13 @@ How do I change the colors in a running kitty instance? You can either use the `OSC terminal escape codes `_ -to set colors or you can enable :doc:`remote control ` -for |kitty| and use :ref:`at_set-colors`. +to set colors or you can define keyboard shortcuts to set colors, for example:: + + map f1 set_colors --configured /path/to/some/config/file/colors.conf + +Or you can enable :doc:`remote control ` for |kitty| and use :ref:`at_set-colors`. +The shortcut mapping technique has the same syntax as the remote control +command, for details, see :ref:`at_set-colors`. A list of pre-made color themes for kitty is available at: `kitty-themes `_ diff --git a/kitty/boss.py b/kitty/boss.py index 530db94a1..088294bcd 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -1096,3 +1096,9 @@ class Boss: msg = '\n'.join(map(format_bad_line, bad_lines)).rstrip() self.show_error(_('Errors in kitty.conf'), msg) + + def set_colors(self, *args): + from .cmds import parse_subcommand_cli, cmd_set_colors, set_colors + opts, items = parse_subcommand_cli(cmd_set_colors, ['set-colors'] + list(args)) + payload = cmd_set_colors(None, opts, items) + set_colors(self, self.active_window, payload) diff --git a/kitty/config.py b/kitty/config.py index 9f5abfafd..558fe400c 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -193,6 +193,15 @@ def pipe(func, rest): return func, rest +@func_with_args('set_colors') +def set_colors(func, rest): + import shlex + rest = shlex.split(rest) + if len(rest) < 1: + log_error('Too few arguments to set_colors function') + return func, rest + + @func_with_args('nth_window') def nth_window(func, rest): try: