diff --git a/docs/changelog.rst b/docs/changelog.rst index 36ea70909..1ef142cb2 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -19,6 +19,9 @@ To update |kitty|, :doc:`follow the instructions `. - macOS: Add an option :opt:`macos_show_window_title_in` to control showing the window title in the menubar/titlebar (:pull:`1837`) +- When running kittens, use the colorscheme of the current window + rather than the configured colorscheme (:iss:`1906`) + - Dont fail to start if running the shell to read the EDITOR env var fails (:iss:`1869`) diff --git a/kitty/boss.py b/kitty/boss.py index 83f86cd56..e10422eca 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -716,7 +716,9 @@ class Boss: }, cwd=w.cwd_of_child, overlay_for=w.id - )) + ), + copy_colors_from=w + ) overlay_window.action_on_close = partial(self.on_kitten_finish, w.id, end_kitten) return overlay_window diff --git a/kitty/colors.c b/kitty/colors.c index f66967801..f1b42386b 100644 --- a/kitty/colors.c +++ b/kitty/colors.c @@ -98,6 +98,15 @@ update_ansi_color_table(ColorProfile *self, PyObject *val) { Py_RETURN_NONE; } +void +copy_color_profile(ColorProfile *dest, ColorProfile *src) { + memcpy(dest->color_table, src->color_table, sizeof(dest->color_table)); + memcpy(dest->orig_color_table, src->orig_color_table, sizeof(dest->color_table)); + memcpy(&dest->configured, &src->configured, sizeof(dest->configured)); + memcpy(&dest->overridden, &src->overridden, sizeof(dest->overridden)); + dest->dirty = true; +} + static PyObject* patch_color_profiles(PyObject *module UNUSED, PyObject *args) { PyObject *spec, *profiles, *v; ColorProfile *self; int change_configured; PyObject *cursor_text_color; diff --git a/kitty/data-types.h b/kitty/data-types.h index d1784830f..5c675c923 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -278,6 +278,7 @@ Cursor* alloc_cursor(void); LineBuf* alloc_linebuf(unsigned int, unsigned int); HistoryBuf* alloc_historybuf(unsigned int, unsigned int, unsigned int); ColorProfile* alloc_color_profile(void); +void copy_color_profile(ColorProfile*, ColorProfile*); PyObject* create_256_color_table(void); PyObject* parse_bytes_dump(PyObject UNUSED *, PyObject *); PyObject* parse_bytes(PyObject UNUSED *, PyObject *); diff --git a/kitty/screen.c b/kitty/screen.c index 84f984399..2a50edb59 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1989,6 +1989,12 @@ is_rectangle_select(Screen *self, PyObject *a UNUSED) { return ans; } +static PyObject* +copy_colors_from(Screen *self, Screen *other) { + copy_color_profile(self->color_profile, other->color_profile); + Py_RETURN_NONE; +} + static PyObject* text_for_selection(Screen *self, PyObject *a UNUSED) { FullSelectionBoundary start, end; @@ -2294,6 +2300,7 @@ static PyMethodDef methods[] = { MND(toggle_alt_screen, METH_NOARGS) MND(reset_callbacks, METH_NOARGS) MND(paste, METH_O) + MND(copy_colors_from, METH_O) {"select_graphic_rendition", (PyCFunction)_select_graphic_rendition, METH_VARARGS, ""}, {NULL} /* Sentinel */ diff --git a/kitty/tabs.py b/kitty/tabs.py index 8ab17c8fd..65bbcc8fc 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -232,9 +232,13 @@ class Tab: # {{{ ans.fork() return ans - def new_window(self, use_shell=True, cmd=None, stdin=None, override_title=None, cwd_from=None, cwd=None, overlay_for=None, env=None, location=None): + def new_window( + self, use_shell=True, cmd=None, stdin=None, override_title=None, + cwd_from=None, cwd=None, overlay_for=None, env=None, location=None, + copy_colors_from=None + ): child = self.launch_child(use_shell=use_shell, cmd=cmd, stdin=stdin, cwd_from=cwd_from, cwd=cwd, env=env) - window = Window(self, child, self.opts, self.args, override_title=override_title) + window = Window(self, child, self.opts, self.args, override_title=override_title, copy_colors_from=copy_colors_from) if overlay_for is not None: overlaid = next(w for w in self.windows if w.id == overlay_for) window.overlay_for = overlay_for @@ -245,8 +249,8 @@ class Tab: # {{{ self.relayout_borders() return window - def new_special_window(self, special_window, location=None): - return self.new_window(False, *special_window, location=location) + def new_special_window(self, special_window, location=None, copy_colors_from=None): + return self.new_window(False, *special_window, location=location, copy_colors_from=copy_colors_from) def close_window(self): if self.windows: diff --git a/kitty/window.py b/kitty/window.py index 643c90155..220d711e3 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -131,7 +131,7 @@ def text_sanitizer(as_ansi, add_wrap_markers): class Window: - def __init__(self, tab, child, opts, args, override_title=None): + def __init__(self, tab, child, opts, args, override_title=None, copy_colors_from=None): self.action_on_close = None self.layout_data = None self.pty_resized_once = False @@ -158,7 +158,10 @@ class Window: self.child, self.opts = child, opts cell_width, cell_height = cell_size_for_window(self.os_window_id) self.screen = Screen(self, 24, 80, opts.scrollback_lines, cell_width, cell_height, self.id) - setup_colors(self.screen, opts) + if copy_colors_from is not None: + self.screen.copy_colors_from(copy_colors_from.screen) + else: + setup_colors(self.screen, opts) @property def title(self):