feat: support 256 colors

resolves #2429
This commit is contained in:
Jan De Dobbeleer 2022-06-22 08:10:35 +02:00 committed by Jan De Dobbeleer
parent dbf82559c1
commit 82b83d1fa4
3 changed files with 11 additions and 4 deletions

View file

@ -3,6 +3,7 @@ package color
import (
"fmt"
"oh-my-posh/environment"
"strconv"
"github.com/gookit/color"
)
@ -78,10 +79,14 @@ func (d *DefaultColors) AnsiColorFromString(colorString string, isBackground boo
return colorFromName
}
style := color.HEX(colorString, isBackground)
if style.IsEmpty() {
return emptyAnsiColor
if !style.IsEmpty() {
return AnsiColor(style.String())
}
return AnsiColor(style.String())
if colorInt, err := strconv.ParseInt(colorString, 10, 8); err == nil {
c := color.C256(uint8(colorInt), isBackground)
return AnsiColor(c.String())
}
return emptyAnsiColor
}
// getAnsiColorFromName returns the color code for a given color name if the name is

View file

@ -17,7 +17,7 @@
},
"color_string": {
"type": "string",
"pattern": "^(#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})|black|red|green|yellow|blue|magenta|cyan|white|default|darkGray|lightRed|lightGreen|lightYellow|lightBlue|lightMagenta|lightCyan|lightWhite|transparent|parentBackground|parentForeground|background|foreground|accent)$",
"pattern": "^(#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})|^([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$|black|red|green|yellow|blue|magenta|cyan|white|default|darkGray|lightRed|lightGreen|lightYellow|lightBlue|lightMagenta|lightCyan|lightWhite|transparent|parentBackground|parentForeground|background|foreground|accent)$",
"title": "Color string",
"description": "https://ohmyposh.dev/docs/configuration/colors",
"format": "color"

View file

@ -17,6 +17,8 @@ Oh My Posh supports multiple different color references, being:
as well as 8 extended ANSI colors:
`darkGray` `lightRed` `lightGreen` `lightYellow` `lightBlue` `lightMagenta` `lightCyan` `lightWhite`
- 256 color palette using their number representation.
For example `0` is black, `1` is red, `2` is green, etc.
- The `transparent` keyword which can be used to create either a transparent foreground override
or transparent background color using the segment's foreground property.
- The `foreground` keyword which can be used to reference the current segment's foreground color.