diff --git a/main.go b/main.go index 893bb46..311940f 100644 --- a/main.go +++ b/main.go @@ -15,10 +15,7 @@ func main() { var open []string var close []string for _, c := range colors { - red := c >> 16 & 0xFF - green := c >> 8 & 0xFF - blue := c & 0xFF - + red, green, blue, _ := c.RGBA() if (float32(red)*0.299 + float32(green)*0.587 + float32(blue)*0.114) > 150.0 { open = append(open, fmt.Sprintf("\u001B[38;2;%d;%d;%dm", 0, 0, 0)) } else { diff --git a/simplecolor/simplecolors.go b/simplecolor/simplecolors.go index a54e8ce..dbf49a1 100644 --- a/simplecolor/simplecolors.go +++ b/simplecolor/simplecolors.go @@ -33,6 +33,34 @@ func (n NamedPalette) ToPalette() color.Palette { return color.Palette(x) } +func (a SimplePalette) Sort() SimplePalette { + sort.Sort(a) + return a +} + +func (a SimplePalette) Join(b SimplePalette) SimplePalette { + m := make(map[SimpleColor]SimpleColor) + r := SimplePalette{} + for _, c := range a { + m[c] = c + } + for _, c := range b { + m[c] = c + } + for _, c := range m { + r = append(r, c) + } + sort.Sort(r) + return r +} + +func (s SimplePalette) Get(index int) SimpleColor { + if index < 0 || index > len(s) { + return FromHexString("#66042d") + } + return s[index] +} + func (s SimplePalette) ToPalette() color.Palette { var x color.Palette for _, c := range s { @@ -68,6 +96,13 @@ func (input SimpleColor) ToExtendedAnsi() SimpleColor { return SimpleColor(uint32(r)<<16 + uint32(g)<<8 + b) } +func (p NamedPalette) ToExtendedAnsi() NamedPalette { + for k, v := range p { + p[k] = v.ToExtendedAnsi() + } + return p +} + func (p SimplePalette) ToExtendedAnsi() (sp SimplePalette) { used := make(map[SimpleColor]bool) for _, x := range p {