From 82b83d1fa45d317f4d60faf8901037df14376315 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 22 Jun 2022 08:10:35 +0200 Subject: [PATCH] feat: support 256 colors resolves #2429 --- src/color/colors.go | 11 ++++++++--- themes/schema.json | 2 +- website/docs/configuration/colors.mdx | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/color/colors.go b/src/color/colors.go index fff74fdb..cdbdab14 100644 --- a/src/color/colors.go +++ b/src/color/colors.go @@ -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 diff --git a/themes/schema.json b/themes/schema.json index 47d86e35..aa28f2d6 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -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" diff --git a/website/docs/configuration/colors.mdx b/website/docs/configuration/colors.mdx index 952e9b20..8e9f5cb0 100644 --- a/website/docs/configuration/colors.mdx +++ b/website/docs/configuration/colors.mdx @@ -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.