mirror of
https://github.com/taigrr/colorhash.git
synced 2026-04-01 18:58:45 -07:00
in-progress commit for hash functionality extension
This commit is contained in:
@@ -3,10 +3,10 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
go_colorhash "github.com/taigrr/colorhash"
|
"github.com/taigrr/colorhash"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
x := go_colorhash.HashString("asdasd")
|
x := colorhash.HashString("asdasd")
|
||||||
fmt.Println(x)
|
fmt.Println(x)
|
||||||
}
|
}
|
||||||
|
|||||||
57
colors.go
57
colors.go
@@ -2,6 +2,9 @@ package colorhash
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image/color"
|
||||||
|
|
||||||
|
"github.com/taigrr/simplecolorpalettes/simplecolor"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -80,10 +83,62 @@ var (
|
|||||||
OnIWhite = ColorString("\033[0;107m%s\033[0m")
|
OnIWhite = ColorString("\033[0;107m%s\033[0m")
|
||||||
)
|
)
|
||||||
|
|
||||||
func ColorString(colorString string) func(...interface{}) string {
|
type ColorSet interface {
|
||||||
|
ToPalette() color.Palette
|
||||||
|
Get(int) color.Color
|
||||||
|
Len() int
|
||||||
|
}
|
||||||
|
|
||||||
|
type StringerPalette []ColorStringer
|
||||||
|
|
||||||
|
func createStringerPalette(backgroundFillMode, disableSmartMode bool, c ...ColorSet) StringerPalette {
|
||||||
|
palette := StringerPalette{}
|
||||||
|
for _, colorSet := range c {
|
||||||
|
for i := 0; i < colorSet.Len(); i++ {
|
||||||
|
palette = append(palette, trueColorString(colorSet.Get(i), backgroundFillMode, disableSmartMode))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return palette
|
||||||
|
}
|
||||||
|
|
||||||
|
// TBD not yet complete
|
||||||
|
func trueColorString(color color.Color, backgroundFillMode, disableSmartMode bool) ColorStringer {
|
||||||
|
fgEsc, bgEsc := 48, 38
|
||||||
|
sprint := func(args ...interface{}) string {
|
||||||
|
r, g, b, _ := color.RGBA()
|
||||||
|
if !disableSmartMode {
|
||||||
|
return fmt.Sprintf("\033[;2;%d;%d;%d;m%s\033[0m\u001B[39m",
|
||||||
|
r, g, b,
|
||||||
|
fmt.Sprint(args...))
|
||||||
|
}
|
||||||
|
esc := fgEsc
|
||||||
|
if backgroundFillMode {
|
||||||
|
esc = bgEsc
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("\033[%d;2;%d;%d;%d;m%s\033[0m\u001B[%dm",
|
||||||
|
esc,
|
||||||
|
r, g, b,
|
||||||
|
fmt.Sprint(args...),
|
||||||
|
esc+1)
|
||||||
|
}
|
||||||
|
return sprint
|
||||||
|
}
|
||||||
|
|
||||||
|
type ColorStringer func(...interface{}) string
|
||||||
|
|
||||||
|
func ColorString(colorString string) ColorStringer {
|
||||||
sprint := func(args ...interface{}) string {
|
sprint := func(args ...interface{}) string {
|
||||||
return fmt.Sprintf(colorString,
|
return fmt.Sprintf(colorString,
|
||||||
fmt.Sprint(args...))
|
fmt.Sprint(args...))
|
||||||
}
|
}
|
||||||
return sprint
|
return sprint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetBackgroundColor(c color.Color) color.Color {
|
||||||
|
red, green, blue, _ := c.RGBA()
|
||||||
|
if (float32(red)*0.299 + float32(green)*0.587 + float32(blue)*0.114) > 150.0 {
|
||||||
|
return simplecolor.FromRGBA(0, 0, 0, 0)
|
||||||
|
}
|
||||||
|
return simplecolor.FromRGBA(255, 255, 255, 0)
|
||||||
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -2,4 +2,4 @@ module github.com/taigrr/colorhash
|
|||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require github.com/taigrr/simplecolorpalettes v0.9.2
|
require github.com/taigrr/simplecolorpalettes v0.9.5
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,2 +1,2 @@
|
|||||||
github.com/taigrr/simplecolorpalettes v0.9.2 h1:ofnMYZWyg00EzaHkoo51bReptkctOmgZDOn3aD1Dcgs=
|
github.com/taigrr/simplecolorpalettes v0.9.5 h1:XPyRYwCHh+0ra/7Qw5c9yQf/O4yeLkuqx2X1tVuBE2U=
|
||||||
github.com/taigrr/simplecolorpalettes v0.9.2/go.mod h1:MFLQqI3JOfSc+8GiO3amYfzBiozxITaQi+F1iEV8XpQ=
|
github.com/taigrr/simplecolorpalettes v0.9.5/go.mod h1:MFLQqI3JOfSc+8GiO3amYfzBiozxITaQi+F1iEV8XpQ=
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestHashBytes(t *testing.T) {
|
func TestHashBytes(t *testing.T) {
|
||||||
testBytes := []struct {
|
testBytes := []struct{}{}
|
||||||
runAsUser bool
|
|
||||||
}{}
|
|
||||||
_ = testBytes
|
_ = testBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user