aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorludovicm67 <ludovicmuller1@gmail.com>2019-08-28 21:13:45 +0200
committerludovicm67 <ludovicmuller1@gmail.com>2019-10-15 20:42:27 +0200
commit75004e1298b530fa2a3231b9c9f25441a32b35d4 (patch)
tree6d8d13f582b85d6d524be857cce4d5a3224b61e0
parentd0d9ea56b9fcb8f2638269b1a6856ef14db7d694 (diff)
downloadgit-bug-75004e1298b530fa2a3231b9c9f25441a32b35d4.tar.gz
bug: rename RGBA to Color
-rw-r--r--bridge/github/export.go2
-rw-r--r--bug/label.go69
-rw-r--r--graphql/resolvers/label.go2
-rw-r--r--termui/label_select.go7
-rw-r--r--termui/show_bug.go5
5 files changed, 52 insertions, 33 deletions
diff --git a/bridge/github/export.go b/bridge/github/export.go
index b239eff9..a79256fc 100644
--- a/bridge/github/export.go
+++ b/bridge/github/export.go
@@ -576,7 +576,7 @@ func (ge *githubExporter) getOrCreateGithubLabelID(ctx context.Context, gc *gith
}
// RGBA to hex color
- rgba := label.RGBA()
+ rgba := label.Color().RGBA()
hexColor := fmt.Sprintf("%.2x%.2x%.2x", rgba.R, rgba.G, rgba.B)
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
diff --git a/bug/label.go b/bug/label.go
index c224f037..1344d97e 100644
--- a/bug/label.go
+++ b/bug/label.go
@@ -15,32 +15,34 @@ func (l Label) String() string {
return string(l)
}
+type LabelColor color.RGBA
+
// RGBA from a Label computed in a deterministic way
-func (l Label) RGBA() color.RGBA {
+func (l Label) Color() LabelColor {
id := 0
hash := sha1.Sum([]byte(l))
// colors from: https://material-ui.com/style/color/
- 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
+ colors := []LabelColor{
+ LabelColor{R: 244, G: 67, B: 54, A: 255}, // red
+ LabelColor{R: 233, G: 30, B: 99, A: 255}, // pink
+ LabelColor{R: 156, G: 39, B: 176, A: 255}, // purple
+ LabelColor{R: 103, G: 58, B: 183, A: 255}, // deepPurple
+ LabelColor{R: 63, G: 81, B: 181, A: 255}, // indigo
+ LabelColor{R: 33, G: 150, B: 243, A: 255}, // blue
+ LabelColor{R: 3, G: 169, B: 244, A: 255}, // lightBlue
+ LabelColor{R: 0, G: 188, B: 212, A: 255}, // cyan
+ LabelColor{R: 0, G: 150, B: 136, A: 255}, // teal
+ LabelColor{R: 76, G: 175, B: 80, A: 255}, // green
+ LabelColor{R: 139, G: 195, B: 74, A: 255}, // lightGreen
+ LabelColor{R: 205, G: 220, B: 57, A: 255}, // lime
+ LabelColor{R: 255, G: 235, B: 59, A: 255}, // yellow
+ LabelColor{R: 255, G: 193, B: 7, A: 255}, // amber
+ LabelColor{R: 255, G: 152, B: 0, A: 255}, // orange
+ LabelColor{R: 255, G: 87, B: 34, A: 255}, // deepOrange
+ LabelColor{R: 121, G: 85, B: 72, A: 255}, // brown
+ LabelColor{R: 158, G: 158, B: 158, A: 255}, // grey
+ LabelColor{R: 96, G: 125, B: 139, A: 255}, // blueGrey
}
for _, char := range hash {
@@ -50,15 +52,26 @@ func (l Label) RGBA() color.RGBA {
return colors[id]
}
-func (l Label) Term256() int {
- rgba := l.RGBA()
- red := int(rgba.R) * 6 / 256
- green := int(rgba.G) * 6 / 256
- blue := int(rgba.B) * 6 / 256
+func (lc LabelColor) RGBA() color.RGBA {
+ return color.RGBA(lc)
+}
+
+type Term256 int
+
+func (lc LabelColor) Term256() Term256 {
+ red := Term256(lc.R) * 6 / 256
+ green := Term256(lc.G) * 6 / 256
+ blue := Term256(lc.B) * 6 / 256
- color256 := red*36 + green*6 + blue + 16
+ return red*36 + green*6 + blue + 16
+}
+
+func (t Term256) Escape() string {
+ return fmt.Sprintf("\x1b[38;5;%dm", t)
+}
- return color256
+func (t Term256) Unescape() string {
+ return "\x1b[0m"
}
func (l Label) Validate() error {
diff --git a/graphql/resolvers/label.go b/graphql/resolvers/label.go
index 690bf7f6..0368a1e6 100644
--- a/graphql/resolvers/label.go
+++ b/graphql/resolvers/label.go
@@ -19,7 +19,7 @@ func (labelResolver) Name(ctx context.Context, obj *bug.Label) (string, error) {
}
func (labelResolver) Color(ctx context.Context, obj *bug.Label) (*color.RGBA, error) {
- rgba := obj.RGBA()
+ rgba := obj.Color().RGBA()
return &rgba, nil
}
diff --git a/termui/label_select.go b/termui/label_select.go
index 131703f9..e0f97279 100644
--- a/termui/label_select.go
+++ b/termui/label_select.go
@@ -127,7 +127,12 @@ func (ls *labelSelect) layout(g *gocui.Gui) error {
if ls.labelSelect[i] {
selectBox = " [x] "
}
- fmt.Fprint(v, selectBox, label)
+
+ lc := label.Color()
+ lc256 := lc.Term256()
+ labelStr := lc256.Escape() + "◼ " + lc256.Unescape() + label.String()
+ fmt.Fprint(v, selectBox, labelStr)
+
y0 += 2
}
diff --git a/termui/show_bug.go b/termui/show_bug.go
index 82d4160e..f9a30b4b 100644
--- a/termui/show_bug.go
+++ b/termui/show_bug.go
@@ -429,8 +429,9 @@ func (sb *showBug) renderSidebar(g *gocui.Gui, sideView *gocui.View) error {
labelStr := make([]string, len(snap.Labels))
for i, l := range snap.Labels {
- color256 := l.Term256()
- labelStr[i] = fmt.Sprintf("\x1b[38;5;%dm◼\x1b[0m %s", color256, string(l))
+ lc := l.Color()
+ lc256 := lc.Term256()
+ labelStr[i] = lc256.Escape() + "◼ " + lc256.Unescape() + l.String()
}
labels := strings.Join(labelStr, "\n")