mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-02 15:07:28 -04:00
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:
+14
-2
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user