From e245e6b2ec2b57cdcaba91ff34e2b34ce8c9a889 Mon Sep 17 00:00:00 2001 From: Alvaro Tinoco Marmol Date: Sat, 18 May 2024 15:21:39 +0200 Subject: [PATCH] fix: support rgb colors closes #9 --- pkg/color/color.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/color/color.go b/pkg/color/color.go index 05b680a..5096a61 100644 --- a/pkg/color/color.go +++ b/pkg/color/color.go @@ -1,15 +1,31 @@ package color import ( + "fmt" + "image/color" + "github.com/hinshun/vt10x" ) //go:generate go run colorsgen.go func GetColor(c vt10x.Color) string { - if c >= 1<<24 { + switch { + case c >= 1<<24: return colors[int(vt10x.LightGrey)] + case c >= 1<<8: + rgb := intToRGB(int(c)) + return fmt.Sprintf("#%02x%02x%02x", rgb.R, rgb.B, rgb.G) + default: + return colors[int(c)] } +} - return colors[int(c)] +func intToRGB(c int) color.RGBA { + return color.RGBA{ + R: uint8(c >> 16), + G: uint8(c >> 8), + B: uint8(c), + A: 255, + } }