mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-12 14:04:05 -08:00
parent
a1801f717c
commit
20462aa50f
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"oh-my-posh/platform"
|
"oh-my-posh/platform"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
)
|
)
|
||||||
|
@ -78,6 +79,14 @@ func (d *DefaultColors) AnsiColorFromString(colorString string, isBackground boo
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return colorFromName
|
return colorFromName
|
||||||
}
|
}
|
||||||
|
if !strings.HasPrefix(colorString, "#") {
|
||||||
|
val, err := strconv.ParseUint(colorString, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return emptyAnsiColor
|
||||||
|
}
|
||||||
|
c256 := color.C256(uint8(val), isBackground)
|
||||||
|
return AnsiColor(c256.RGBColor().String())
|
||||||
|
}
|
||||||
style := color.HEX(colorString, isBackground)
|
style := color.HEX(colorString, isBackground)
|
||||||
if !style.IsEmpty() {
|
if !style.IsEmpty() {
|
||||||
return AnsiColor(style.String())
|
return AnsiColor(style.String())
|
||||||
|
|
|
@ -13,6 +13,8 @@ func TestGetAnsiFromColorString(t *testing.T) {
|
||||||
Color string
|
Color string
|
||||||
Background bool
|
Background bool
|
||||||
}{
|
}{
|
||||||
|
{Case: "256 color", Expected: AnsiColor("38;2;135;95;255"), Color: "99", Background: false},
|
||||||
|
{Case: "256 color", Expected: AnsiColor("38;2;135;255;215"), Color: "122", Background: false},
|
||||||
{Case: "Invalid background", Expected: emptyAnsiColor, Color: "invalid", Background: true},
|
{Case: "Invalid background", Expected: emptyAnsiColor, Color: "invalid", Background: true},
|
||||||
{Case: "Invalid background", Expected: emptyAnsiColor, Color: "invalid", Background: false},
|
{Case: "Invalid background", Expected: emptyAnsiColor, Color: "invalid", Background: false},
|
||||||
{Case: "Hex foreground", Expected: AnsiColor("38;2;170;187;204"), Color: "#AABBCC", Background: false},
|
{Case: "Hex foreground", Expected: AnsiColor("38;2;170;187;204"), Color: "#AABBCC", Background: false},
|
||||||
|
|
Loading…
Reference in a new issue