From abf9cce6bff6a30f86a6b5a23e0e9a3b84209563 Mon Sep 17 00:00:00 2001 From: pagedown Date: Thu, 4 Nov 2021 18:27:55 +0800 Subject: [PATCH] When the color is set to none get-colors should not return a color value --- kitty/colors.c | 17 +++++++++++------ kitty/fast_data_types.pyi | 2 +- kitty/rc/get_colors.py | 6 +++++- kitty/window.py | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/kitty/colors.c b/kitty/colors.c index f3d165e56..71eca3218 100644 --- a/kitty/colors.c +++ b/kitty/colors.c @@ -211,7 +211,7 @@ colorprofile_to_color_with_fallback(ColorProfile *self, DynamicColor entry, Dyna static PyObject* as_dict(ColorProfile *self, PyObject *args UNUSED) { -#define as_dict_doc "Return all colors as a dictionary of color_name to integer (names are the same as used in kitty.conf)" +#define as_dict_doc "Return all colors as a dictionary of color_name to integer or None (names are the same as used in kitty.conf)" PyObject *ans = PyDict_New(); if (ans == NULL) return PyErr_NoMemory(); for (unsigned i = 0; i < arraysz(self->color_table); i++) { @@ -225,11 +225,16 @@ as_dict(ColorProfile *self, PyObject *args UNUSED) { } #define D(attr, name) { \ if (self->overridden.attr.type != COLOR_NOT_SET) { \ - color_type c = colorprofile_to_color(self, self->overridden.attr, self->configured.attr).rgb; \ - PyObject *val = PyLong_FromUnsignedLong(c); \ - if (!val) { Py_CLEAR(ans); return PyErr_NoMemory(); } \ - int ret = PyDict_SetItemString(ans, #name, val); \ - Py_CLEAR(val); \ + int ret; \ + if (self->overridden.attr.type == COLOR_IS_SPECIAL) { \ + ret = PyDict_SetItemString(ans, #name, Py_None); \ + } else { \ + color_type c = colorprofile_to_color(self, self->overridden.attr, self->configured.attr).rgb; \ + PyObject *val = PyLong_FromUnsignedLong(c); \ + if (!val) { Py_CLEAR(ans); return PyErr_NoMemory(); } \ + ret = PyDict_SetItemString(ans, #name, val); \ + Py_CLEAR(val); \ + } \ if (ret != 0) { Py_CLEAR(ans); return NULL; } \ }} D(default_fg, foreground); D(default_bg, background); diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 5b55d4360..909250b55 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -682,7 +682,7 @@ class ColorProfile: default_bg: int - def as_dict(self) -> Dict[str, int]: + def as_dict(self) -> Dict[str, Optional[int]]: pass def as_color(self, val: int) -> Optional[Color]: diff --git a/kitty/rc/get_colors.py b/kitty/rc/get_colors.py index 3fc177bbd..8015cafb6 100644 --- a/kitty/rc/get_colors.py +++ b/kitty/rc/get_colors.py @@ -45,7 +45,11 @@ configured colors. ans = {k: getattr(opts, k) for k in opts if isinstance(getattr(opts, k), Color)} if not payload_get('configured'): windows = self.windows_for_match_payload(boss, window, payload_get) - ans.update({k: color_from_int(v) for k, v in windows[0].current_colors.items()}) + for k, v in windows[0].current_colors.items(): + if v is None: + ans.pop(k, None) + else: + ans[k] = color_from_int(v) all_keys = natsort_ints(ans) maxlen = max(map(len, all_keys)) return '\n'.join(('{:%ds} {}' % maxlen).format(key, color_as_sharp(ans[key])) for key in all_keys) diff --git a/kitty/window.py b/kitty/window.py index 1451caa27..663cdd832 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -494,7 +494,7 @@ class Window: } @property - def current_colors(self) -> Dict[str, int]: + def current_colors(self) -> Dict[str, Optional[int]]: return self.screen.color_profile.as_dict() @property