JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.02k stars 2.37k forks source link

Oh My Posh custom theme backgound_template color being ignored #3544

Closed mkanet closed 1 year ago

mkanet commented 1 year ago

Code of Conduct

What happened?

Version: 14.9.2 (amd64) Windows 10 22H2 PowerShell 5.1

I made a simple custom theme based on existing Oh My Posh themes and documentation (see theme code section below). However, no matter what I do, I can't force the background_templates condition to use the specified color when the condition is met. In fact, any color I specify in the condition seems to be treated as a null value.

NOTE: The condition is detected correctly when the respective environment variable's value is detected... However, it is not changing the color of the first couple of segments to #ff0000 aka RED. It looks like it sets the color to NULL. There are no syntax errors. I'm not sure what I'm missing.

Expected behavior: Expected

Actual Behavior: Actual

Could you please tell me what I'm doing wrong? I've spent a great deal of time trying to get this to work before asking for help.

Thank you in advance for your assistance.

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "alignment": "left",
      "segments": [
        {
          "background": "#42E66C",
          "background_templates": [
            "{{ if eq .Env.ElevatedPINNotAuthorized \"True\" }} #ff0000 {{ end }}"
          ],
          "foreground": "#ffffff",
          "leading_diamond": "\ue0b6",
          "style": "diamond",
          "template": " {{ if .WSL }}WSL at {{ end }}{{.Icon}} ",
          "type": "os"
        },
        {
          "background": "#42E66C",
          "background_templates": [
            "{{ if eq .Env.ElevatedPINNotAuthorized \"True\" }} #ff0000 {{ end }}"
          ],
          "foreground": "#ffffff",
          "style": "powerline",
          "template": " {{ .Env.CyberCredential }} ",
          "type": "session"
        },
        {
          "background": "lightBlue",
          "foreground": "black",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "style": "full"
          },
          "style": "powerline",
          "template": " \ue5ff {{ .Path }} ",
          "type": "path"
        },
        {
          "background": "#ec9706",
          "foreground": "#100e23",
          "leading_diamond": "<transparent,background>\ue0b0</>",
          "properties": {
            "always_enabled": true
          },
          "style": "diamond",
          "template": " \ufbab {{ .FormattedMs }}\u2800",
          "trailing_diamond": "\ue0b0",
          "type": "executiontime"
        }
      ],
      "type": "prompt"
    }
  ],
  "final_space": true,
  "version": 2
}

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Please forgive me, I couldn't find in the documentation how to enable log output.  The only thing I could find was [debug prompt](https://ohmyposh.dev/docs/configuration/debug-prompt) code, didn't look like it applied to this case.
JanDeDobbeleer commented 1 year ago

@mkanet your background template has a leading and trailing space in the resulting color string which evaluates as invalid. As we do not trim (and not plan to), removing the spaces will result in a working setup:

"background_templates": [
    "{{ if eq .Env.ElevatedPINNotAuthorized \"True\" }}#ff0000{{ end }}"
],
mkanet commented 1 year ago

@JanDeDobbeleer thank you so much for telling me what I did wrong. I'm embarrassed to say how much time I spent looking for the solution to this!

I really appreciate your hard work keeping Oh My Posh updated. It's my new favorite MS Terminal toy.

github-actions[bot] commented 10 months ago

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 first, complete the body with all the details necessary to reproduce, and mention this issue as reference.