desktop-ui: Fix an invalid accent_color breaking the appearance settings

This commit is contained in:
devangpratap 2026-10-26 14:05:23 -04:00
parent a2086eb6a4
commit 2519974e84
3 changed files with 37 additions and 4 deletions

View file

@ -26,7 +26,12 @@ The color scheme for your system. This sets the initial value of the color schem
by using :code:`kitten desktop-ui color-scheme`.
""",
)
opt('accent_color', 'cyan', long_text='The RGB accent color for your system, can be specified as a color name or in hex a decimal format.')
opt(
'accent_color',
'cyan',
option_type='to_color',
long_text='The RGB accent color for your system, can be specified as a color name or in hex a decimal format.',
)
opt('contrast', 'normal', choices=('normal', 'high'), long_text='The preferred contrast level.')
opt(
'file_chooser_size',

View file

@ -71,9 +71,14 @@ type Portal struct {
file_chooser_first_instance_exited chan struct{}
}
func color_variant(col style.RGBA) dbus.Variant {
return dbus.MakeVariant([]float64{float64(col.Red) / 255., float64(col.Green) / 255., float64(col.Blue) / 255.})
}
func to_color(spec string) (v dbus.Variant, err error) {
if col, err := style.ParseColor(spec); err == nil {
return dbus.MakeVariant([]float64{float64(col.Red) / 255., float64(col.Green) / 255., float64(col.Blue) / 255.}), nil
col, err := style.ParseColor(spec)
if err == nil {
v = color_variant(col)
}
return
}
@ -94,7 +99,7 @@ func NewPortal(opts *Config, server_options *ServerOptions) (p *Portal, err erro
default:
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_COLOR_SCHEME_KEY] = dbus.MakeVariant(uint32(NO_PREFERENCE))
}
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_ACCENT_COLOR_KEY], err = to_color(opts.Accent_color)
ans.settings[PORTAL_APPEARANCE_NAMESPACE][PORTAL_ACCENT_COLOR_KEY] = color_variant(opts.Accent_color)
var contrast uint32
if opts.Contrast == Contrast_high {
contrast = 1

View file

@ -0,0 +1,23 @@
// License: GPLv3 Copyright: 2026, kitty contributors
package desktop_ui
import (
"testing"
)
func TestInvalidAccentColor(t *testing.T) {
if _, err := to_color("cyan"); err != nil {
t.Fatalf("Valid accent color rejected: %s", err)
}
if v, err := to_color("not-a-color"); err == nil {
t.Fatalf("Invalid accent color accepted as: %#v", v)
}
c := NewConfig()
if err := c.Parse("accent_color", "not-a-color"); err == nil {
t.Fatalf("Invalid accent_color accepted in config as: %#v", c.Accent_color)
}
if c.Accent_color != NewConfig().Accent_color {
t.Fatalf("Invalid accent_color in config changed the default to: %#v", c.Accent_color)
}
}