Closed lyricnz closed 2 years ago
Something like this?
// NewColorscheme ...
func NewColorscheme(colors ColorschemeColors) *Colorscheme {
// Build lookup table for defined values, then replace references to these
const prefix = "define_"
const reference = "&"
defines := ColorschemeColors{}
for k, v := range colors {
if strings.HasPrefix(k, prefix) {
defines[k[len(prefix):]] = v
}
}
for k, v := range colors {
if vs, ok := v.(string); ok {
if strings.HasPrefix(vs, reference) {
colors[k] = defines[vs[len(reference):]]
}
}
}
return &Colorscheme{
colors: colors,
cache: make(ColorCache),
cacheMutex: sync.RWMutex{},
}
}
Included as part of https://github.com/cointop-sh/cointop/pull/232
It would be nice if you could define a logical name, then reuse it throughout the file - this would make it easier to update many values at once.