Skip to content

Commit

Permalink
fix: support rgb colors
Browse files Browse the repository at this point in the history
closes #9
  • Loading branch information
MrMarble committed May 18, 2024
1 parent b791093 commit e245e6b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/color/color.go
Original file line number Diff line number Diff line change
@@ -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,
}
}

0 comments on commit e245e6b

Please sign in to comment.