Support hex color values in style config

While we don't support extended color ranges just yet, this approximates
the hex value to the closest color value in the ANSI 256-color chart.
This commit is contained in:
Christian Muehlhaeuser
2019-12-05 11:43:56 +01:00
parent 31ad9136b5
commit 39a6da5fe7
4 changed files with 69 additions and 2 deletions
+14 -2
View File
@@ -24,13 +24,25 @@ func renderText(w io.Writer, rules *ElementStyle, s string) {
if rules != nil {
if rules.Color != "" {
i, err := strconv.Atoi(rules.Color)
var i int
var err error
if rules.Color[0] == '#' {
i, err = hexToANSIColor(rules.Color)
} else {
i, err = strconv.Atoi(rules.Color)
}
if err == nil && i >= 0 && i <= 255 {
out = out.Index(uint8(i))
}
}
if rules.BackgroundColor != "" {
i, err := strconv.Atoi(rules.BackgroundColor)
var i int
var err error
if rules.BackgroundColor[0] == '#' {
i, err = hexToANSIColor(rules.BackgroundColor)
} else {
i, err = strconv.Atoi(rules.BackgroundColor)
}
if err == nil && i >= 0 && i <= 255 {
out = out.BgIndex(uint8(i))
}