From 862c8657be33ddd389fe576c00363aa454a3d566 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 29 Oct 2026 08:52:08 +0530 Subject: [PATCH] Cleanup previous PR Make ColorProfile.test_mark_colors() return MARK_MASK pairs instead of a hard-coded three, simplify the test by using MARK_MASK and mutable expected values, and correct the changelog entry: config reload was not affected, set-colors, launch --color, sessions and automatic theme switching were. --- docs/changelog.rst | 6 ++++-- kitty/colors.c | 14 +++++++++++--- kitty/fast_data_types.pyi | 2 +- kitty_tests/screen.py | 35 ++++++++++++++++++++--------------- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 146b16e89..7ab6cd496 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -231,8 +231,10 @@ Detailed list of changes 0.50.0 [future] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Fix live text-marker color updates applying each foreground/background pair - to the next marker instead of its own marker. +- Fix changing text marker colors at runtime, for example with + :code:`kitten @ set-colors` or automatic dark/light theme switching, applying + the colors of each marker to the next one, with changes to ``mark3`` having + no effect - Allow docking kitty windows to the edges of other windows or of the tab, for status bars, file trees, etc. Create them with :code:`launch --type=window-dock` diff --git a/kitty/colors.c b/kitty/colors.c index db175f6d8..6bf6f0819 100644 --- a/kitty/colors.c +++ b/kitty/colors.c @@ -1140,16 +1140,24 @@ set_transparent_background_color(ColorProfile *self, PyObject *const *args, Py_s Py_RETURN_NONE; } -// Test the same marker slots consumed by the renderer without clearing pending uploads. +// Return the (fg, bg) pair for each mark, as uploaded to the GPU, without +// clearing pending uploads. The buffer layout must match copy_color_table_to_buffer(). static PyObject * test_mark_colors(ColorProfile *self, PyObject *unused UNUSED) { color_type buf[arraysz(self->color_table) + arraysz(self->mark_backgrounds) + arraysz(self->mark_foregrounds) + NUM_INDEXED_IMAGE_SPECIAL_COLORS]; - bool dirty = self->dirty; + const bool dirty = self->dirty; copy_color_table_to_buffer(self, buf, 0, 1); self->dirty = dirty; const color_type *bg = buf + arraysz(self->color_table); const color_type *fg = bg + arraysz(self->mark_backgrounds); - return Py_BuildValue("((II)(II)(II))", fg[0], bg[0], fg[1], bg[1], fg[2], bg[2]); + RAII_PyObject(ans, PyTuple_New(MARK_MASK)); + if (!ans) return NULL; + for (size_t i = 0; i < MARK_MASK; i++) { + PyObject *pair = Py_BuildValue("II", fg[i], bg[i]); + if (!pair) return NULL; + PyTuple_SET_ITEM(ans, i, pair); + } + return Py_NewRef(ans); } static PyMethodDef cp_methods[] = { diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index b0cb9978f..42c792aa2 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -823,7 +823,7 @@ class ColorProfile: def set_transparent_background_color(self, index: int, color: Color | None = None, opacity: float | None = None) -> None: ... def reset_layer(self, layer: int) -> None: ... def color_stack_depth(self) -> int: ... - def test_mark_colors(self) -> tuple[tuple[int, int], tuple[int, int], tuple[int, int]]: ... + def test_mark_colors(self) -> tuple[tuple[int, int], ...]: ... def patch_color_profiles( spec: Dict[str, Optional[int]], diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index bfe511442..f9e301939 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -2369,33 +2369,38 @@ class TestScreen(BaseTest): self.assertEqual('continued' in row, which_screen == 0 and i == 1, row) def test_live_mark_colors(self): - from kitty.fast_data_types import COLOR_LAYER_GLOBAL, patch_color_profiles + from kitty.fast_data_types import COLOR_LAYER_GLOBAL, MARK_MASK, patch_color_profiles opts = self.set_options({'palette_generate': 'fixed'}) profiles = tuple(ColorProfile(opts) for _ in range(3)) + marks = range(1, MARK_MASK + 1) + channels = ('foreground', 'background') def configured(): - return tuple(tuple(int(getattr(opts, f'mark{i}_{channel}')) for channel in ('foreground', 'background')) for i in range(1, 4)) + return [[int(getattr(opts, f'mark{m}_{ch}')) for ch in channels] for m in marks] + + def ae(cp, expected): + self.ae([list(pair) for pair in cp.test_mark_colors()], expected) - expected = configured() for cp in profiles: - self.ae(cp.test_mark_colors(), expected) + ae(cp, configured()) + # Patch all marks in the first two profiles, the third must be unaffected for base in (0x123400, 0x567800): - spec = {f'mark{i}_{channel}': base + 2 * i + j for i in range(1, 4) for j, channel in enumerate(('foreground', 'background'))} + spec = {f'mark{m}_{ch}': base + 2 * m + j for m in marks for j, ch in enumerate(channels)} patch_color_profiles(spec, None, profiles[:2], COLOR_LAYER_GLOBAL) - expected = tuple((spec[f'mark{i}_foreground'], spec[f'mark{i}_background']) for i in range(1, 4)) + expected = [[spec[f'mark{m}_{ch}'] for ch in channels] for m in marks] for cp in profiles[:2]: - self.ae(cp.test_mark_colors(), expected) - self.ae(profiles[2].test_mark_colors(), configured()) - for i in range(3): - for j, channel in enumerate(('foreground', 'background')): - value = 0xABCD00 + 2 * i + j - patch_color_profiles({f'mark{i + 1}_{channel}': value}, None, profiles[:1], COLOR_LAYER_GLOBAL) - expected = tuple(tuple(value if (r, c) == (i, j) else v for c, v in enumerate(pair)) for r, pair in enumerate(expected)) - self.ae(profiles[0].test_mark_colors(), expected) + ae(cp, expected) + ae(profiles[2], configured()) + # Patching a single channel of a single mark must not affect the others + for i, m in enumerate(marks): + for j, ch in enumerate(channels): + expected[i][j] = 0xABCD00 + 2 * i + j + patch_color_profiles({f'mark{m}_{ch}': expected[i][j]}, None, profiles[:1], COLOR_LAYER_GLOBAL) + ae(profiles[0], expected) for reset in (False, True): profiles[0].reload_from_opts(opts, reset_overriden_colors=reset) - self.ae(profiles[0].test_mark_colors(), configured()) + ae(profiles[0], configured()) def test_color_profile(self): from kitty.fast_data_types import patch_color_profiles