From df02769ed1140f968b5f9f594af66adeb3c9a8b3 Mon Sep 17 00:00:00 2001 From: Zhizhen He Date: Fri, 30 Oct 2026 23:05:31 +0800 Subject: [PATCH] themes: Isolate picker cache from unicode_input --- docs/changelog.rst | 3 +++ kittens/themes/main.go | 6 ++++- kittens/themes/main_test.go | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 kittens/themes/main_test.go diff --git a/docs/changelog.rst b/docs/changelog.rst index a362453b6..f4bbd6413 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -425,6 +425,9 @@ Detailed list of changes silently died and fix colors 16-255 being set to white with themes that do not define them (:iss:`10691`, :iss:`10661`, :pull:`10727`, :pull:`10737`) +- Themes kitten: Fix overwriting the Unicode input kitten's recent entries + and input mode, and vice versa, by using separate caches + - Transfer kitten: When receiving files, replace existing symbolic and hard links at the destination instead of overwriting the files they point to, and write to a temporary file that is renamed into place, so an interrupted diff --git a/kittens/themes/main.go b/kittens/themes/main.go index 1b0ff065b..2770338bd 100644 --- a/kittens/themes/main.go +++ b/kittens/themes/main.go @@ -19,6 +19,10 @@ import ( var _ = fmt.Print +func new_cached_values() *utils.CachedValues[*CachedData] { + return utils.NewCachedValues("themes", &CachedData{Category: "All"}) +} + func complete_themes(completions *cli.Completions, word string, arg_num int) { themes.CompleteThemes(completions, word, arg_num) } @@ -63,7 +67,7 @@ func main(_ *cli.Command, opts *Options, args []string) (rc int, err error) { if err != nil { return 1, err } - cv := utils.NewCachedValues("unicode-input", &CachedData{Category: "All"}) + cv := new_cached_values() h := &handler{lp: lp, opts: opts, cached_data: cv.Load()} defer cv.Save() lp.OnInitialize = func() (string, error) { diff --git a/kittens/themes/main_test.go b/kittens/themes/main_test.go new file mode 100644 index 000000000..cd2b179d6 --- /dev/null +++ b/kittens/themes/main_test.go @@ -0,0 +1,50 @@ +// License: GPLv3 Copyright: 2026, Kovid Goyal, + +package themes + +import ( + "reflect" + "testing" + + "github.com/kovidgoyal/kitty/kittens/unicode_input" + "github.com/kovidgoyal/kitty/tools/utils" +) + +func TestPickerCachesAreIndependent(t *testing.T) { + original_cache_dir := utils.CacheDir + t.Cleanup(func() { utils.CacheDir = original_cache_dir }) + for _, themes_last := range []bool{false, true} { + name := "unicode_after_themes" + if themes_last { + name = "themes_after_unicode" + } + t.Run(name, func(t *testing.T) { + cache_dir := t.TempDir() + utils.CacheDir = func() string { return cache_dir } + want_themes := &CachedData{Category: "dark", Recent: []string{"Gruvbox Dark"}} + want_unicode := &unicode_input.CachedData{Mode: "NAME", Recent: []rune{'π', '♥'}} + themes_cache := new_cached_values() + unicode_cache := utils.NewCachedValues("unicode-input", &unicode_input.CachedData{Mode: unicode_input.DEFAULT_MODE}) + if themes_last { + unicode_cache.Opts = want_unicode + unicode_cache.Save() + themes_cache.Load() + themes_cache.Opts = want_themes + themes_cache.Save() + } else { + themes_cache.Opts = want_themes + themes_cache.Save() + unicode_cache.Load() + unicode_cache.Opts = want_unicode + unicode_cache.Save() + } + if got := new_cached_values().Load(); !reflect.DeepEqual(got, want_themes) { + t.Errorf("theme preferences changed: got %#v, want %#v", got, want_themes) + } + got_unicode := utils.NewCachedValues("unicode-input", &unicode_input.CachedData{Mode: unicode_input.DEFAULT_MODE}).Load() + if !reflect.DeepEqual(got_unicode, want_unicode) { + t.Errorf("Unicode input preferences changed: got %#v, want %#v", got_unicode, want_unicode) + } + }) + } +}