mirror of
https://github.com/taigrr/simplecolorpalettes.git
synced 2026-04-01 20:49:11 -07:00
use builtins, add joining funcs
This commit is contained in:
5
main.go
5
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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user