mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-17 05:32:41 +00:00
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:
parent
9a8c61d402
commit
de43c108f5
3 changed files with 57 additions and 0 deletions
|
|
@ -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`)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
51
tools/cmd/at/set_colors_test.go
Normal file
51
tools/cmd/at/set_colors_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue