use builtins, add joining funcs

This commit is contained in:
2022-10-10 01:35:47 -07:00
parent 4104eb60c8
commit b6cfa96e93
2 changed files with 36 additions and 4 deletions

View File

@@ -15,10 +15,7 @@ func main() {
var open []string var open []string
var close []string var close []string
for _, c := range colors { for _, c := range colors {
red := c >> 16 & 0xFF red, green, blue, _ := c.RGBA()
green := c >> 8 & 0xFF
blue := c & 0xFF
if (float32(red)*0.299 + float32(green)*0.587 + float32(blue)*0.114) > 150.0 { 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)) open = append(open, fmt.Sprintf("\u001B[38;2;%d;%d;%dm", 0, 0, 0))
} else { } else {

View File

@@ -33,6 +33,34 @@ func (n NamedPalette) ToPalette() color.Palette {
return color.Palette(x) 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 { func (s SimplePalette) ToPalette() color.Palette {
var x color.Palette var x color.Palette
for _, c := range s { for _, c := range s {
@@ -68,6 +96,13 @@ func (input SimpleColor) ToExtendedAnsi() SimpleColor {
return SimpleColor(uint32(r)<<16 + uint32(g)<<8 + b) 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) { func (p SimplePalette) ToExtendedAnsi() (sp SimplePalette) {
used := make(map[SimpleColor]bool) used := make(map[SimpleColor]bool)
for _, x := range p { for _, x := range p {