fix(ansi): print 256 correctly

resolves #3533
This commit is contained in:
Jan De Dobbeleer 2023-02-26 15:28:45 +01:00 committed by Jan De Dobbeleer
parent bd4d916b0a
commit c844bd871e
4 changed files with 6 additions and 5 deletions

View file

@ -124,7 +124,7 @@ func (d *DefaultColors) ToColor(colorString string, isBackground bool) Color {
return emptyColor return emptyColor
} }
c256 := color.C256(uint8(val), isBackground) c256 := color.C256(uint8(val), isBackground)
return Color(c256.RGBColor().String()) return Color(c256.String())
} }
style := color.HEX(colorString, isBackground) style := color.HEX(colorString, isBackground)
if !style.IsEmpty() { if !style.IsEmpty() {

View file

@ -13,8 +13,8 @@ func TestGetAnsiFromColorString(t *testing.T) {
Color string Color string
Background bool Background bool
}{ }{
{Case: "256 color", Expected: Color("38;2;135;95;255"), Color: "99", Background: false}, {Case: "256 color", Expected: Color("38;5;99"), Color: "99", Background: false},
{Case: "256 color", Expected: Color("38;2;135;255;215"), Color: "122", Background: false}, {Case: "256 color", Expected: Color("38;5;122"), Color: "122", Background: false},
{Case: "Invalid background", Expected: emptyColor, Color: "invalid", Background: true}, {Case: "Invalid background", Expected: emptyColor, Color: "invalid", Background: true},
{Case: "Invalid background", Expected: emptyColor, Color: "invalid", Background: false}, {Case: "Invalid background", Expected: emptyColor, Color: "invalid", Background: false},
{Case: "Hex foreground", Expected: Color("38;2;170;187;204"), Color: "#AABBCC", Background: false}, {Case: "Hex foreground", Expected: Color("38;2;170;187;204"), Color: "#AABBCC", Background: false},

View file

@ -8,7 +8,7 @@ sidebar_label: Colors
Oh My Posh supports multiple different color references, being: Oh My Posh supports multiple different color references, being:
- Typical [hex colors][hexcolors] (for example `#CB4B16`). - True color using [hex colors][hexcolors] (for example `#CB4B16`).
- 16 [ANSI color names][ansicolors]. - 16 [ANSI color names][ansicolors].
These include 8 basic ANSI colors and `default` These include 8 basic ANSI colors and `default`

View file

@ -11,7 +11,7 @@ import Next from "./next.mdx";
## Set up your terminal ## Set up your terminal
As the standard terminal has issues displaying the ANSI characters correctly, we advise using As the standard terminal only support [256 colors][256-colors], we advise using
[iTerm2][iterm2] or any other modern day macOS terminal that supports ANSI characters. [iTerm2][iterm2] or any other modern day macOS terminal that supports ANSI characters.
:::info :::info
@ -24,6 +24,7 @@ To display all icons, we recommend the use of a [Nerd Font][fonts].
<Next /> <Next />
[256-colors]: /docs/configuration/colors#standard-colors
[fonts]: /docs/installation/fonts [fonts]: /docs/installation/fonts
[scoop]: https://scoop.sh/ [scoop]: https://scoop.sh/
[wt]: https://github.com/microsoft/terminal [wt]: https://github.com/microsoft/terminal