Fix colors 16-255 being set to white by ssh and themes kittens when theme leaves them unset
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run

Fixes #10661
This commit is contained in:
Kovid Goyal 2026-10-13 14:03:22 +05:30
parent 4b977494c5
commit 32a77d3cf7
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
4 changed files with 45 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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()
}

View file

@ -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)
}
}