diff --git a/docs/changelog.rst b/docs/changelog.rst index 98121550b..0917ffa72 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -235,6 +235,8 @@ Detailed list of changes status bars, file trees, etc. Create them with :code:`launch --type=window-dock` or :code:`launch --type=tab-dock`, see :ref:`docks` +- ssh kitten, themes kitten: Fix colors 16-255 being set to white when using a color theme that does not define them (:iss:`10661`) + - quick-access-terminal kitten: A new :option:`kitty +kitten quick_access_terminal --if-running` option to run a program in a new tab or window of an already running quick access terminal and a new :option:`kitty +kitten quick_access_terminal --listen-on` option diff --git a/gen/go_code.py b/gen/go_code.py index 6165f6a8e..2023c74e8 100755 --- a/gen/go_code.py +++ b/gen/go_code.py @@ -35,7 +35,7 @@ from kitty.cli import ( from kitty.conf.generate import gen_go_code from kitty.conf.types import Definition from kitty.config import commented_out_default_config -from kitty.fast_data_types import all_color_names +from kitty.fast_data_types import NULL_COLOR_VALUE, all_color_names, default_color_table from kitty.guess_mime_type import known_extensions, text_mimes from kitty.key_encoding import config_mod_map from kitty.key_names import character_key_name_aliases, functional_key_name_aliases @@ -647,6 +647,11 @@ def generate_color_names() -> str: + '\n\nvar ColorTable = [256]uint32{' + ', '.join(f'{x}' for x in Options.color_table) + '}\n' + + '\n// Fixed values for entries in ColorTable that are unset (NullColorValue)\n' + + 'var FixedColorTable = [256]uint32{' + + ', '.join(f'{x}' for x in default_color_table()) + + '}\n' + + f'\nconst NullColorValue uint32 = {NULL_COLOR_VALUE}\n' + f''' var DefaultColors = struct {{ Foreground, Background, Cursor, SelectionFg, SelectionBg string diff --git a/tools/themes/collection.go b/tools/themes/collection.go index 355c6d77f..885ec3315 100644 --- a/tools/themes/collection.go +++ b/tools/themes/collection.go @@ -691,6 +691,7 @@ func ColorSettingsAsEscapeCodes(settings map[string]string) string { set_default_color("selection_background", style.DefaultColors.SelectionBg, loop.SELECTION_BG) set_default_color("selection_foreground", style.DefaultColors.SelectionFg, loop.SELECTION_FG) + unset := make([]int, 0, 256) w.WriteString("\033]4") for i := range 256 { key := "color" + strconv.Itoa(i) @@ -702,11 +703,27 @@ func ColorSettingsAsEscapeCodes(settings map[string]string) string { continue } } + c := style.ColorTable[i] + if c == style.NullColorValue { + // Use the fixed palette for terminals that don't support OSC 21 + c = style.FixedColorTable[i] + unset = append(unset, i) + } rgba := style.RGBA{} - rgba.FromRGB(style.ColorTable[i]) + rgba.FromRGB(c) set_color(i, rgba.AsRGBSharp()) } w.WriteString("\033\\") + if len(unset) > 0 { + // Have kitty fill in unset colors based on its palette_generate setting + w.WriteString("\033]21") + for _, i := range unset { + w.WriteByte(';') + w.WriteString(strconv.Itoa(i)) + w.WriteByte('=') + } + w.WriteString("\033\\") + } return w.String() } diff --git a/tools/themes/collection_test.go b/tools/themes/collection_test.go index 2d0378934..7bf18ef7c 100644 --- a/tools/themes/collection_test.go +++ b/tools/themes/collection_test.go @@ -163,3 +163,22 @@ func TestThemeCollections(t *testing.T) { t.Fatal("failed to load code for alabaster theme") } } + +func TestColorSettingsAsEscapeCodes(t *testing.T) { + ans := ColorSettingsAsEscapeCodes(map[string]string{"color1": "#ff0000", "color17": "#00ff00"}) + for _, q := range []string{";1;#ff0000;", ";17;#00ff00;", ";16;#000000;", ";255;#eeeeee\x1b\\"} { + if !strings.Contains(ans, q) { + t.Fatalf("%#v not found in %#v", q, ans) + } + } + if strings.Contains(ans, ";16;#ffffff") { + t.Fatalf("Unset color 16 was set to white: %#v", ans) + } + _, osc21, found := strings.Cut(ans, "\x1b]21;") + if !found { + t.Fatalf("No OSC 21 in %#v", ans) + } + if !strings.HasPrefix(osc21, "16=;18=;") || !strings.HasSuffix(osc21, ";255=\x1b\\") || strings.Contains(osc21, ";17=") { + t.Fatalf("Incorrect OSC 21: %#v", osc21) + } +}