Skip to content

Commit 75004e1

Browse files
committed
bug: rename RGBA to Color
1 parent d0d9ea5 commit 75004e1

File tree

5 files changed

+52
-33
lines changed

5 files changed

+52
-33
lines changed

bridge/github/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func (ge *githubExporter) getOrCreateGithubLabelID(ctx context.Context, gc *gith
576576
}
577577

578578
// RGBA to hex color
579-
rgba := label.RGBA()
579+
rgba := label.Color().RGBA()
580580
hexColor := fmt.Sprintf("%.2x%.2x%.2x", rgba.R, rgba.G, rgba.B)
581581

582582
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)

bug/label.go

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,34 @@ func (l Label) String() string {
1515
return string(l)
1616
}
1717

18+
type LabelColor color.RGBA
19+
1820
// RGBA from a Label computed in a deterministic way
19-
func (l Label) RGBA() color.RGBA {
21+
func (l Label) Color() LabelColor {
2022
id := 0
2123
hash := sha1.Sum([]byte(l))
2224

2325
// colors from: https://material-ui.com/style/color/
24-
colors := []color.RGBA{
25-
color.RGBA{R: 244, G: 67, B: 54, A: 255}, // red
26-
color.RGBA{R: 233, G: 30, B: 99, A: 255}, // pink
27-
color.RGBA{R: 156, G: 39, B: 176, A: 255}, // purple
28-
color.RGBA{R: 103, G: 58, B: 183, A: 255}, // deepPurple
29-
color.RGBA{R: 63, G: 81, B: 181, A: 255}, // indigo
30-
color.RGBA{R: 33, G: 150, B: 243, A: 255}, // blue
31-
color.RGBA{R: 3, G: 169, B: 244, A: 255}, // lightBlue
32-
color.RGBA{R: 0, G: 188, B: 212, A: 255}, // cyan
33-
color.RGBA{R: 0, G: 150, B: 136, A: 255}, // teal
34-
color.RGBA{R: 76, G: 175, B: 80, A: 255}, // green
35-
color.RGBA{R: 139, G: 195, B: 74, A: 255}, // lightGreen
36-
color.RGBA{R: 205, G: 220, B: 57, A: 255}, // lime
37-
color.RGBA{R: 255, G: 235, B: 59, A: 255}, // yellow
38-
color.RGBA{R: 255, G: 193, B: 7, A: 255}, // amber
39-
color.RGBA{R: 255, G: 152, B: 0, A: 255}, // orange
40-
color.RGBA{R: 255, G: 87, B: 34, A: 255}, // deepOrange
41-
color.RGBA{R: 121, G: 85, B: 72, A: 255}, // brown
42-
color.RGBA{R: 158, G: 158, B: 158, A: 255}, // grey
43-
color.RGBA{R: 96, G: 125, B: 139, A: 255}, // blueGrey
26+
colors := []LabelColor{
27+
LabelColor{R: 244, G: 67, B: 54, A: 255}, // red
28+
LabelColor{R: 233, G: 30, B: 99, A: 255}, // pink
29+
LabelColor{R: 156, G: 39, B: 176, A: 255}, // purple
30+
LabelColor{R: 103, G: 58, B: 183, A: 255}, // deepPurple
31+
LabelColor{R: 63, G: 81, B: 181, A: 255}, // indigo
32+
LabelColor{R: 33, G: 150, B: 243, A: 255}, // blue
33+
LabelColor{R: 3, G: 169, B: 244, A: 255}, // lightBlue
34+
LabelColor{R: 0, G: 188, B: 212, A: 255}, // cyan
35+
LabelColor{R: 0, G: 150, B: 136, A: 255}, // teal
36+
LabelColor{R: 76, G: 175, B: 80, A: 255}, // green
37+
LabelColor{R: 139, G: 195, B: 74, A: 255}, // lightGreen
38+
LabelColor{R: 205, G: 220, B: 57, A: 255}, // lime
39+
LabelColor{R: 255, G: 235, B: 59, A: 255}, // yellow
40+
LabelColor{R: 255, G: 193, B: 7, A: 255}, // amber
41+
LabelColor{R: 255, G: 152, B: 0, A: 255}, // orange
42+
LabelColor{R: 255, G: 87, B: 34, A: 255}, // deepOrange
43+
LabelColor{R: 121, G: 85, B: 72, A: 255}, // brown
44+
LabelColor{R: 158, G: 158, B: 158, A: 255}, // grey
45+
LabelColor{R: 96, G: 125, B: 139, A: 255}, // blueGrey
4446
}
4547

4648
for _, char := range hash {
@@ -50,15 +52,26 @@ func (l Label) RGBA() color.RGBA {
5052
return colors[id]
5153
}
5254

53-
func (l Label) Term256() int {
54-
rgba := l.RGBA()
55-
red := int(rgba.R) * 6 / 256
56-
green := int(rgba.G) * 6 / 256
57-
blue := int(rgba.B) * 6 / 256
55+
func (lc LabelColor) RGBA() color.RGBA {
56+
return color.RGBA(lc)
57+
}
58+
59+
type Term256 int
60+
61+
func (lc LabelColor) Term256() Term256 {
62+
red := Term256(lc.R) * 6 / 256
63+
green := Term256(lc.G) * 6 / 256
64+
blue := Term256(lc.B) * 6 / 256
5865

59-
color256 := red*36 + green*6 + blue + 16
66+
return red*36 + green*6 + blue + 16
67+
}
68+
69+
func (t Term256) Escape() string {
70+
return fmt.Sprintf("\x1b[38;5;%dm", t)
71+
}
6072

61-
return color256
73+
func (t Term256) Unescape() string {
74+
return "\x1b[0m"
6275
}
6376

6477
func (l Label) Validate() error {

graphql/resolvers/label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (labelResolver) Name(ctx context.Context, obj *bug.Label) (string, error) {
1919
}
2020

2121
func (labelResolver) Color(ctx context.Context, obj *bug.Label) (*color.RGBA, error) {
22-
rgba := obj.RGBA()
22+
rgba := obj.Color().RGBA()
2323
return &rgba, nil
2424
}
2525

termui/label_select.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ func (ls *labelSelect) layout(g *gocui.Gui) error {
127127
if ls.labelSelect[i] {
128128
selectBox = " [x] "
129129
}
130-
fmt.Fprint(v, selectBox, label)
130+
131+
lc := label.Color()
132+
lc256 := lc.Term256()
133+
labelStr := lc256.Escape() + "◼ " + lc256.Unescape() + label.String()
134+
fmt.Fprint(v, selectBox, labelStr)
135+
131136
y0 += 2
132137
}
133138

termui/show_bug.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,9 @@ func (sb *showBug) renderSidebar(g *gocui.Gui, sideView *gocui.View) error {
429429

430430
labelStr := make([]string, len(snap.Labels))
431431
for i, l := range snap.Labels {
432-
color256 := l.Term256()
433-
labelStr[i] = fmt.Sprintf("\x1b[38;5;%dm◼\x1b[0m %s", color256, string(l))
432+
lc := l.Color()
433+
lc256 := lc.Term256()
434+
labelStr[i] = lc256.Escape() + "◼ " + lc256.Unescape() + l.String()
434435
}
435436

436437
labels := strings.Join(labelStr, "\n")

0 commit comments

Comments
 (0)