"tokyonight" found TokyoNight, the first case-insensitive match, where VHS's Set Theme takes the scheme of that exact name.
- commit
- 391e1d51801fb0bc47999986efb348708336735b
- parent
- 55928ef00d21eba0ed272fbcadf24a1ff6dbf6f1
- author
- Dami <dami.etoile@gmail.com>
- kind
- fix risk score 1.6 of 3, Jev's estimate
| M | internal/ | 10 | ++++++---- |
| M | internal/ | 3 | +++ |
@@ -145,9 +145,10 @@ func userPalettes(dir string) []Palette {
145145 }146146 147147 // Lookup finds a scheme by name: a file in dir first (named exactly, or148-// with .json or .conf), then a built-in. Names match case-insensitively,149-// and then ignoring spaces, hyphens and underscores, so "tokyo-night"150-// finds "TokyoNight".148+// with .json or .conf), then a built-in. Names match exactly, then149+// case-insensitively, then ignoring spaces, hyphens and underscores, so150+// "tokyo-night" finds "TokyoNight" and "tokyonight" the scheme of that151+// name.151152 func Lookup(name, dir string) (Palette, error) {152153 if dir != "" && !strings.ContainsAny(name, `/\`) && name != "." && name != ".." {153154 for _, file := range []string{name, name + ".json", name + ".conf"} {@@ -159,7 +160,8 @@ func Lookup(name, dir string) (Palette, error) {
159160 }160161 }161162 all := append(userPalettes(dir), Builtins()...)162- for _, match := range []func(string) string{strings.ToLower, squash} {163+ same := func(s string) string { return s }164+ for _, match := range []func(string) string{same, strings.ToLower, squash} {163165 for _, p := range all {164166 if match(p.Name) == match(name) {165167 return p, nil@@ -29,6 +29,9 @@ func TestBuiltins(t *testing.T) {
2929 if err != nil || p.Name != "TokyoNight" {3030 t.Errorf("loose match: %q %v", p.Name, err)3131 }32+ if p, err := Lookup("tokyonight", ""); err != nil || p.Name != "tokyonight" {33+ t.Errorf("exact name: %q %v", p.Name, err)34+ }3235 if _, err := Lookup("No Such Theme", ""); err == nil || !strings.Contains(err.Error(), "012 config themes") {3336 t.Errorf("unknown: %v", err)3437 }