set-colors: Ignore color arguments when resetting colors

Skip color argument parsing for --reset, as documented and already done
by the Python command path. Add a payload-creation regression covering
invalid colors, missing files and valid colors with and without reset.
This commit is contained in:
Zhizhen He 2026-10-20 00:54:13 +08:00
parent 9a8c61d402
commit de43c108f5
No known key found for this signature in database
GPG key ID: B5A215D74FCFD6A7
3 changed files with 57 additions and 0 deletions

View file

@ -261,6 +261,9 @@ Detailed list of changes
arguments, such as non-numbers or NaN, as zero opacity instead of reporting
an error
- Remote control: Fix ``kitten @ set-colors --reset`` failing on invalid
color arguments or missing configuration files instead of ignoring them
- ssh kitten: Fix hanging when re-using a shared connection whose connection
to the server has silently died, for example, after a network change or
suspend. Now the kitten detects this and reconnects (:iss:`10691`)

View file

@ -294,6 +294,9 @@ func set_color_in_color_map(key, val string, ans map[string]any, check_nullable,
func parse_colors_and_files(args []string) (map[string]any, error) {
ans := make(map[string]any, len(args))
if options_set_colors.Reset {
return ans, nil
}
for _, arg := range args {
key, val, found := strings.Cut(strings.ToLower(arg), "=")
if found {

View file

@ -0,0 +1,51 @@
// License: GPLv3 Copyright: 2026, kitty contributors
package at
import (
"fmt"
"path/filepath"
"testing"
"github.com/kovidgoyal/kitty/tools/utils"
)
func TestSetColorsResetIgnoresArguments(t *testing.T) {
original_reset := options_set_colors.Reset
t.Cleanup(func() { options_set_colors.Reset = original_reset })
missing_file := filepath.Join(t.TempDir(), "missing.conf")
for _, reset := range []bool{false, true} {
for _, test := range []struct {
name, arg string
invalid bool
}{
{"invalid-color", "foreground=not-a-color", true},
{"missing-file", missing_file, true},
{"valid-color", "foreground=red", false},
} {
t.Run(fmt.Sprintf("%s/reset=%t", test.name, reset), func(t *testing.T) {
options_set_colors.Reset = reset
io_data := rc_io_data{rc: &utils.RemoteControlCmd{}}
err := create_payload_set_colors(&io_data, nil, []string{test.arg})
want_error := test.invalid && !reset
if (err != nil) != want_error {
t.Fatalf("expected error=%t, got: %v", want_error, err)
}
if err != nil {
return
}
payload := io_data.rc.Payload.(set_colors_json_type)
if payload.Reset != reset {
t.Fatalf("expected reset=%t, got: %#v", reset, payload)
}
if reset {
if len(payload.Colors) != 0 {
t.Fatalf("--reset did not ignore color arguments: %#v", payload.Colors)
}
} else if payload.Colors["foreground"] != uint32(0xff0000) {
t.Fatalf("foreground was not parsed: %#v", payload.Colors)
}
})
}
}
}