aboutsummaryrefslogtreecommitdiffstats
path: root/bug/label.go
diff options
context:
space:
mode:
authorludovicm67 <ludovicmuller1@gmail.com>2019-03-28 15:50:32 +0100
committerQuentin Gliech <quentingliech@gmail.com>2019-05-22 20:22:34 +0200
commit1d94fd1b31fd391709c8a80238f2fe87a35800ff (patch)
tree0144dd15c8464cb7f08f567408d87f6c9c74350a /bug/label.go
parent93bed322faf962d75eb85360dcac362822e6cdb4 (diff)
downloadgit-bug-1d94fd1b31fd391709c8a80238f2fe87a35800ff.tar.gz
core: format and add some comments for color label
Diffstat (limited to 'bug/label.go')
-rw-r--r--bug/label.go44
1 files changed, 23 insertions, 21 deletions
diff --git a/bug/label.go b/bug/label.go
index 058e4572..accfdfbf 100644
--- a/bug/label.go
+++ b/bug/label.go
@@ -8,10 +8,11 @@ import (
"github.com/MichaelMure/git-bug/util/text"
)
+// Color in the form red, green, blue
type Color struct {
- red uint8
+ red uint8
green uint8
- blue uint8
+ blue uint8
}
type Label string
@@ -20,35 +21,36 @@ func (l Label) String() string {
return string(l)
}
+// Color from a Label in a deterministic way
func (l Label) Color() Color {
label := string(l)
id := 0
// colors from: https://material-ui.com/style/color/
colors := []Color{
- Color{red: 244, green: 67, blue: 54}, // red
- Color{red: 233, green: 30, blue: 99}, // pink
- Color{red: 156, green: 39, blue: 176}, // purple
- Color{red: 103, green: 58, blue: 183}, // deepPurple
- Color{red: 63, green: 81, blue: 181}, // indigo
- Color{red: 33, green: 150, blue: 243}, // blue
- Color{red: 3, green: 169, blue: 244}, // lightBlue
- Color{red: 0, green: 188, blue: 212}, // cyan
- Color{red: 0, green: 150, blue: 136}, // teal
- Color{red: 76, green: 175, blue: 80}, // green
- Color{red: 139, green: 195, blue: 74}, // lightGreen
- Color{red: 205, green: 220, blue: 57}, // lime
- Color{red: 255, green: 235, blue: 59}, // yellow
- Color{red: 255, green: 193, blue: 7}, // amber
- Color{red: 255, green: 152, blue: 0}, // orange
- Color{red: 255, green: 87, blue: 34}, // deepOrange
- Color{red: 121, green: 85, blue: 72}, // brown
+ Color{red: 244, green: 67, blue: 54}, // red
+ Color{red: 233, green: 30, blue: 99}, // pink
+ Color{red: 156, green: 39, blue: 176}, // purple
+ Color{red: 103, green: 58, blue: 183}, // deepPurple
+ Color{red: 63, green: 81, blue: 181}, // indigo
+ Color{red: 33, green: 150, blue: 243}, // blue
+ Color{red: 3, green: 169, blue: 244}, // lightBlue
+ Color{red: 0, green: 188, blue: 212}, // cyan
+ Color{red: 0, green: 150, blue: 136}, // teal
+ Color{red: 76, green: 175, blue: 80}, // green
+ Color{red: 139, green: 195, blue: 74}, // lightGreen
+ Color{red: 205, green: 220, blue: 57}, // lime
+ Color{red: 255, green: 235, blue: 59}, // yellow
+ Color{red: 255, green: 193, blue: 7}, // amber
+ Color{red: 255, green: 152, blue: 0}, // orange
+ Color{red: 255, green: 87, blue: 34}, // deepOrange
+ Color{red: 121, green: 85, blue: 72}, // brown
Color{red: 158, green: 158, blue: 158}, // grey
- Color{red: 96, green: 125, blue: 139}, // blueGrey
+ Color{red: 96, green: 125, blue: 139}, // blueGrey
}
for pos, char := range label {
- id = (pos + id + int(char)) % len(colors)
+ id = ((pos+1)*(id+1) + int(char)) % len(colors)
}
return colors[id]