Repository: JanDeDobbeleer/oh-my-posh (Go)

Issue:
256-color mode not working on macos
### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

### What happened?

With commit 20462aa support for the 256 color mode has been added. Unfortunately in a way which doesn't work on terminals which don't support truecolor mode (like the Terminal on macOS)

I would expect that if I use a 256 color code to specify the color, something like `5;<color_code>` is used, but not `2;<red>;<green>;<blue>`

I'm wondering if it was intentionally to use `c256.RGBColor().String()` and not `c256.String()` to get the ANSI escape sequence?


### Theme

my own theme using 256 color codes.

### What OS are you seeing the problem on?

macOS

### Which shell are you using?

zsh

### Log output

```Shell
not relevant for this kind of issue
```



Discussion:
@dueckminor fair point, resolved and incoming.

<img width="794" alt="image" src="https://user-images.githubusercontent.com/2492783/221416418-2fbd0859-db6d-4176-a963-4e29ed7ec3cf.png">
I also thought about how to fix this:
https://github.com/dueckminor/oh-my-posh/commit/50fe4badcb407173ce0c2156905c2c5a57de3451

Using `color.IsSupportTrueColor()` might help for themes which are using RGB colors. It would be also possible to translate RGB to the nearest 256 color code. But I feat that `color.IsSupportTrueColor()` is not really reliable and will report very often that only 256 colors are supported, even if the terminal has truecolor support.

@JanDeDobbeleer If you think that this makes sense, I could work on a PR.
@dueckminor it's easier to leverage color palettes and check for those terminals in the template rather than baking in some half reliable functionality for the very few terminals out there which don't support true color.
This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a [discussion](https://github.com/JanDeDobbeleer/oh-my-posh/discussions/new?category=troubleshoot) first, complete the body with all the details necessary to reproduce, and mention this issue as reference.



Patch:
diff --git a/src/ansi/colors.go b/src/ansi/colors.go
index 6a30b9663bf2..7dfac2224ace 100644
--- a/src/ansi/colors.go
+++ b/src/ansi/colors.go
@@ -124,7 +124,7 @@ func (d *DefaultColors) ToColor(colorString string, isBackground bool) Color {
 			return emptyColor
 		}
 		c256 := color.C256(uint8(val), isBackground)
-		return Color(c256.RGBColor().String())
+		return Color(c256.String())
 	}
 	style := color.HEX(colorString, isBackground)
 	if !style.IsEmpty() {
diff --git a/website/docs/configuration/colors.mdx b/website/docs/configuration/colors.mdx
index 1c8a45b4c8b0..2d70e16df157 100644
--- a/website/docs/configuration/colors.mdx
+++ b/website/docs/configuration/colors.mdx
@@ -8,7 +8,7 @@ sidebar_label: Colors
 
 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].
   These include 8 basic ANSI colors and `default`
 
diff --git a/website/docs/installation/macos.mdx b/website/docs/installation/macos.mdx
index 243b062c67ba..9745347fec0d 100644
--- a/website/docs/installation/macos.mdx
+++ b/website/docs/installation/macos.mdx
@@ -11,7 +11,7 @@ import Next from "./next.mdx";
 
 ## 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.
 
 :::info
@@ -24,6 +24,7 @@ To display all icons, we recommend the use of a [Nerd Font][fonts].
 
 <Next />
 
+[256-colors]: /docs/configuration/colors#standard-colors
 [fonts]: /docs/installation/fonts
 [scoop]: https://scoop.sh/
 [wt]: https://github.com/microsoft/terminal


Test patch:
diff --git a/src/ansi/colors_test.go b/src/ansi/colors_test.go
index 0b0847a419a4..018d08ebdffc 100644
--- a/src/ansi/colors_test.go
+++ b/src/ansi/colors_test.go
@@ -13,8 +13,8 @@ func TestGetAnsiFromColorString(t *testing.T) {
 		Color      string
 		Background bool
 	}{
-		{Case: "256 color", Expected: Color("38;2;135;95;255"), 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;99"), Color: "99", 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: false},
 		{Case: "Hex foreground", Expected: Color("38;2;170;187;204"), Color: "#AABBCC", Background: false},