Skip to content

Commit e245e6b

Browse files
committed
fix: support rgb colors
closes #9
1 parent b791093 commit e245e6b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

pkg/color/color.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
package color
22

33
import (
4+
"fmt"
5+
"image/color"
6+
47
"github.com/hinshun/vt10x"
58
)
69

710
//go:generate go run colorsgen.go
811

912
func GetColor(c vt10x.Color) string {
10-
if c >= 1<<24 {
13+
switch {
14+
case c >= 1<<24:
1115
return colors[int(vt10x.LightGrey)]
16+
case c >= 1<<8:
17+
rgb := intToRGB(int(c))
18+
return fmt.Sprintf("#%02x%02x%02x", rgb.R, rgb.B, rgb.G)
19+
default:
20+
return colors[int(c)]
1221
}
22+
}
1323

14-
return colors[int(c)]
24+
func intToRGB(c int) color.RGBA {
25+
return color.RGBA{
26+
R: uint8(c >> 16),
27+
G: uint8(c >> 8),
28+
B: uint8(c),
29+
A: 255,
30+
}
1531
}

0 commit comments

Comments
 (0)