When the color is set to none get-colors should not return a color value

This commit is contained in:
pagedown 2021-11-04 18:27:55 +08:00
parent d9c400ac32
commit abf9cce6bf
No known key found for this signature in database
GPG Key ID: E921CF18AC8FF6EB
4 changed files with 18 additions and 9 deletions

View File

@ -211,7 +211,7 @@ colorprofile_to_color_with_fallback(ColorProfile *self, DynamicColor entry, Dyna
static PyObject* static PyObject*
as_dict(ColorProfile *self, PyObject *args UNUSED) { 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(); PyObject *ans = PyDict_New();
if (ans == NULL) return PyErr_NoMemory(); if (ans == NULL) return PyErr_NoMemory();
for (unsigned i = 0; i < arraysz(self->color_table); i++) { 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) { \ #define D(attr, name) { \
if (self->overridden.attr.type != COLOR_NOT_SET) { \ if (self->overridden.attr.type != COLOR_NOT_SET) { \
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; \ color_type c = colorprofile_to_color(self, self->overridden.attr, self->configured.attr).rgb; \
PyObject *val = PyLong_FromUnsignedLong(c); \ PyObject *val = PyLong_FromUnsignedLong(c); \
if (!val) { Py_CLEAR(ans); return PyErr_NoMemory(); } \ if (!val) { Py_CLEAR(ans); return PyErr_NoMemory(); } \
int ret = PyDict_SetItemString(ans, #name, val); \ ret = PyDict_SetItemString(ans, #name, val); \
Py_CLEAR(val); \ Py_CLEAR(val); \
} \
if (ret != 0) { Py_CLEAR(ans); return NULL; } \ if (ret != 0) { Py_CLEAR(ans); return NULL; } \
}} }}
D(default_fg, foreground); D(default_bg, background); D(default_fg, foreground); D(default_bg, background);

View File

@ -682,7 +682,7 @@ class ColorProfile:
default_bg: int default_bg: int
def as_dict(self) -> Dict[str, int]: def as_dict(self) -> Dict[str, Optional[int]]:
pass pass
def as_color(self, val: int) -> Optional[Color]: def as_color(self, val: int) -> Optional[Color]:

View File

@ -45,7 +45,11 @@ configured colors.
ans = {k: getattr(opts, k) for k in opts if isinstance(getattr(opts, k), Color)} ans = {k: getattr(opts, k) for k in opts if isinstance(getattr(opts, k), Color)}
if not payload_get('configured'): if not payload_get('configured'):
windows = self.windows_for_match_payload(boss, window, payload_get) 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) all_keys = natsort_ints(ans)
maxlen = max(map(len, all_keys)) maxlen = max(map(len, all_keys))
return '\n'.join(('{:%ds} {}' % maxlen).format(key, color_as_sharp(ans[key])) for key in all_keys) return '\n'.join(('{:%ds} {}' % maxlen).format(key, color_as_sharp(ans[key])) for key in all_keys)

View File

@ -494,7 +494,7 @@ class Window:
} }
@property @property
def current_colors(self) -> Dict[str, int]: def current_colors(self) -> Dict[str, Optional[int]]:
return self.screen.color_profile.as_dict() return self.screen.color_profile.as_dict()
@property @property