aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bug/label.go52
-rw-r--r--bug/label_test.go31
2 files changed, 39 insertions, 44 deletions
diff --git a/bug/label.go b/bug/label.go
index f658d0b2..08f122b4 100644
--- a/bug/label.go
+++ b/bug/label.go
@@ -3,51 +3,45 @@ package bug
import (
"crypto/sha1"
"fmt"
+ "image/color"
"io"
"strings"
"github.com/MichaelMure/git-bug/util/text"
)
-// RGBColor is a color type in the form red, green, blue
-type RGBColor struct {
- red uint8
- green uint8
- blue uint8
-}
-
type Label string
func (l Label) String() string {
return string(l)
}
-// RGBColor from a Label computed in a deterministic way
-func (l Label) RGBColor() RGBColor {
+// RGBA from a Label computed in a deterministic way
+func (l Label) RGBA() color.RGBA {
id := 0
hash := sha1.Sum([]byte(l))
// colors from: https://material-ui.com/style/color/
- colors := []RGBColor{
- RGBColor{red: 244, green: 67, blue: 54}, // red
- RGBColor{red: 233, green: 30, blue: 99}, // pink
- RGBColor{red: 156, green: 39, blue: 176}, // purple
- RGBColor{red: 103, green: 58, blue: 183}, // deepPurple
- RGBColor{red: 63, green: 81, blue: 181}, // indigo
- RGBColor{red: 33, green: 150, blue: 243}, // blue
- RGBColor{red: 3, green: 169, blue: 244}, // lightBlue
- RGBColor{red: 0, green: 188, blue: 212}, // cyan
- RGBColor{red: 0, green: 150, blue: 136}, // teal
- RGBColor{red: 76, green: 175, blue: 80}, // green
- RGBColor{red: 139, green: 195, blue: 74}, // lightGreen
- RGBColor{red: 205, green: 220, blue: 57}, // lime
- RGBColor{red: 255, green: 235, blue: 59}, // yellow
- RGBColor{red: 255, green: 193, blue: 7}, // amber
- RGBColor{red: 255, green: 152, blue: 0}, // orange
- RGBColor{red: 255, green: 87, blue: 34}, // deepOrange
- RGBColor{red: 121, green: 85, blue: 72}, // brown
- RGBColor{red: 158, green: 158, blue: 158}, // grey
- RGBColor{red: 96, green: 125, blue: 139}, // blueGrey
+ colors := []color.RGBA{
+ color.RGBA{R: 244, G: 67, B: 54, A: 255}, // red
+ color.RGBA{R: 233, G: 30, B: 99, A: 255}, // pink
+ color.RGBA{R: 156, G: 39, B: 176, A: 255}, // purple
+ color.RGBA{R: 103, G: 58, B: 183, A: 255}, // deepPurple
+ color.RGBA{R: 63, G: 81, B: 181, A: 255}, // indigo
+ color.RGBA{R: 33, G: 150, B: 243, A: 255}, // blue
+ color.RGBA{R: 3, G: 169, B: 244, A: 255}, // lightBlue
+ color.RGBA{R: 0, G: 188, B: 212, A: 255}, // cyan
+ color.RGBA{R: 0, G: 150, B: 136, A: 255}, // teal
+ color.RGBA{R: 76, G: 175, B: 80, A: 255}, // green
+ color.RGBA{R: 139, G: 195, B: 74, A: 255}, // lightGreen
+ color.RGBA{R: 205, G: 220, B: 57, A: 255}, // lime
+ color.RGBA{R: 255, G: 235, B: 59, A: 255}, // yellow
+ color.RGBA{R: 255, G: 193, B: 7, A: 255}, // amber
+ color.RGBA{R: 255, G: 152, B: 0, A: 255}, // orange
+ color.RGBA{R: 255, G: 87, B: 34, A: 255}, // deepOrange
+ color.RGBA{R: 121, G: 85, B: 72, A: 255}, // brown
+ color.RGBA{R: 158, G: 158, B: 158, A: 255}, // grey
+ color.RGBA{R: 96, G: 125, B: 139, A: 255}, // blueGrey
}
for _, char := range hash {
diff --git a/bug/label_test.go b/bug/label_test.go
index 2fb080c0..f87c7411 100644
--- a/bug/label_test.go
+++ b/bug/label_test.go
@@ -1,35 +1,36 @@
package bug
import (
+ "image/color"
"testing"
"github.com/stretchr/testify/require"
)
-func TestLabelRGBColor(t *testing.T) {
- color := Label("test").RGBColor()
- expected := RGBColor{red: 255, green: 87, blue: 34}
+func TestLabelRGBA(t *testing.T) {
+ rgba := Label("test").RGBA()
+ expected := color.RGBA{R: 255, G: 87, B: 34, A: 255}
- require.Equal(t, expected, color)
+ require.Equal(t, expected, rgba)
}
-func TestLabelRGBColorSimilar(t *testing.T) {
- color := Label("test1").RGBColor()
- expected := RGBColor{red: 0, green: 188, blue: 212}
+func TestLabelRGBASimilar(t *testing.T) {
+ rgba := Label("test1").RGBA()
+ expected := color.RGBA{R: 0, G: 188, B: 212, A: 255}
- require.Equal(t, expected, color)
+ require.Equal(t, expected, rgba)
}
-func TestLabelRGBColorReverse(t *testing.T) {
- color := Label("tset").RGBColor()
- expected := RGBColor{red: 233, green: 30, blue: 99}
+func TestLabelRGBAReverse(t *testing.T) {
+ rgba := Label("tset").RGBA()
+ expected := color.RGBA{R: 233, G: 30, B: 99, A: 255}
- require.Equal(t, expected, color)
+ require.Equal(t, expected, rgba)
}
-func TestLabelRGBColorEqual(t *testing.T) {
- color1 := Label("test").RGBColor()
- color2 := Label("test").RGBColor()
+func TestLabelRGBAEqual(t *testing.T) {
+ color1 := Label("test").RGBA()
+ color2 := Label("test").RGBA()
require.Equal(t, color1, color2)
}