Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

internal/palette: fixed a bug due to which the wrong colors could be set for functions on subsequent launches #15

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions internal/palette/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/fs"
"io/ioutil"
"path/filepath"
"sort"
"strings"

"gopkg.in/yaml.v2"
Expand All @@ -18,6 +19,11 @@ type Config struct {
Palette map[string][]ConfigRule
}

type groupRules struct {
name string
rules []ConfigRule
}

// OpenPaletteFromFile returns a ready-use palette from a file.
func OpenPaletteFromFile(path string) (*Palette, error) {
data, err := ioutil.ReadFile(path)
Expand Down Expand Up @@ -62,10 +68,21 @@ In .yaml syntax, it's a map from a string key (description) to a list (rules)`,
func parsePaletteRaw(path string, config *Config) (*Palette, error) {
pal := NewPalette()

for _, group := range config.Palette {
groups := make([]groupRules, 0, len(config.Palette))
for name, group := range config.Palette {
var singleGroup groupRules
singleGroup.name = name
singleGroup.rules = group
groups = append(groups, singleGroup)
}
sort.Slice(groups, func(i, j int) bool {
return groups[i].name < groups[j].name
})

for _, group := range groups {
var rules []*Rule

for _, rule := range group {
for _, rule := range group.rules {
var colorsRaw, desc string
for rColor, rDesc := range rule {
colorsRaw = rColor
Expand Down