JanDeDobbeleer / oh-my-posh

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

`parentBackground` breaks last symbol in `powerline` and `diamond` #1433

Closed thanhph111 closed 2 years ago

thanhph111 commented 2 years ago

Code of Conduct

What happened?

  1. Let's take the default Aliens theme.
  2. Change a background field to parentBackground like in my images below.
  3. We've got a glitch.
Screenshot with git Screenshot without git
Screenshot with git Screenshot without git

I've been using Oh My Posh from the very beginning, just upgraded from an old version. While it doesn't give me the same depth of control as the PowerShell version did, to be honest, it still makes me very happy. Thank you for creating a great tool.

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "session",
          "style": "diamond",
          "foreground": "#ffffff",
          "background": "#61AFEF",
          "leading_diamond": "\uE0B6",
          "trailing_diamond": "\uE0B0"
        },
        {
          "type": "path",
          "style": "powerline",
          "powerline_symbol": "\uE0B0",
          "foreground": "#ffffff",
          "background": "parentBackground",
          "properties": {
            "style": "full"
          }
        },
        {
          "type": "git",
          "style": "powerline",
          "powerline_symbol": "\uE0B0",
          "foreground": "#193549",
          "background": "#95ffa4",
          "properties": {
            "template": "{{ .HEAD }}"
          }
        },
        {
          "type": "python",
          "style": "diamond",
          "foreground": "#ffffff",
          "background": "parentBackground",
          "leading_diamond": "<transparent,background>\uE0B0</>",
          "trailing_diamond": "\uE0B4"
        }
      ]
    }
  ],
  "final_space": true
}

What OS are you seeing the problem on?

Linux

Which shell are you using?

bash, powershell

Log output

Version: 6.33.0

Segments:

ConsoleTitle(false) -   0 ms - 
session(true)  -   0 ms -  thanhph111@T-1000 
path(true)     -   0 ms -  ~/Desktop/temp 
git(true)      -   0 ms -  master 
python(false)  -   0 ms - 

Run duration: 693.702µs

Logs:

2021/12/14 23:50:44 debug: getenv

2021/12/14 23:50:44 getenv duration: 4.615µs, args: XDG_CACHE_HOME
2021/12/14 23:50:44 getCachePath duration: 16.294µs, args: 
2021/12/14 23:50:44 getArgs duration: 57ns, args: 
2021/12/14 23:50:44 getArgs duration: 29ns, args: 
2021/12/14 23:50:44 getShellName duration: 190ns, args: 
2021/12/14 23:50:44 debug: getenv

2021/12/14 23:50:44 getenv duration: 1.164µs, args: OMP_CACHE_DISABLED
2021/12/14 23:50:44 isRunningAsRoot duration: 543ns, args: 
2021/12/14 23:50:44 getcwd duration: 14.346µs, args: 
2021/12/14 23:50:44 getPathSeperator duration: 46ns, args: 
2021/12/14 23:50:44 getPathSeperator duration: 27ns, args: 
2021/12/14 23:50:44 getPathSeperator duration: 28ns, args: 
2021/12/14 23:50:44 getPathSeperator duration: 30ns, args: 
2021/12/14 23:50:44 getPathSeperator duration: 42ns, args: 
2021/12/14 23:50:44 getPathSeperator duration: 29ns, args: 
2021/12/14 23:50:44 getShellName duration: 66ns, args: 
2021/12/14 23:50:44 getCurrentUser duration: 154ns, args: 
2021/12/14 23:50:44 getHostName duration: 1.31µs, args: 
2021/12/14 23:50:44 getcwd duration: 82ns, args: 
2021/12/14 23:50:44 debug: getenv

2021/12/14 23:50:44 getenv duration: 989ns, args: SSH_CONNECTION
2021/12/14 23:50:44 debug: getenv

2021/12/14 23:50:44 getenv duration: 770ns, args: SSH_CLIENT
2021/12/14 23:50:44 getCurrentUser duration: 188ns, args: 
2021/12/14 23:50:44 getRuntimeGOOS duration: 46ns, args: 
2021/12/14 23:50:44 getHostName duration: 873ns, args: 
2021/12/14 23:50:44 debug: getenv

2021/12/14 23:50:44 getenv duration: 606ns, args: POSH_SESSION_DEFAULT_USER
2021/12/14 23:50:44 getcwd duration: 58ns, args: 
2021/12/14 23:50:44 getcwd duration: 27ns, args: 
2021/12/14 23:50:44 getArgs duration: 33ns, args: 
2021/12/14 23:50:44 getcwd duration: 31ns, args: 
2021/12/14 23:50:44 getRuntimeGOOS duration: 33ns, args: 
2021/12/14 23:50:44 getRuntimeGOOS duration: 29ns, args: 
2021/12/14 23:50:44 getPathSeperator duration: 49ns, args: 
2021/12/14 23:50:44 getRuntimeGOOS duration: 28ns, args: 
2021/12/14 23:50:44 getcwd duration: 37ns, args:
JanDeDobbeleer commented 2 years ago

@thanhph111 this syntax is actually not supported as we do not loop the colors:

"background": "parentBackground",
"leading_diamond": "<transparent,background>\uE0B0</>",

it means in the diamond, background translates to parentBackground which isn't resolved to the actual color and falls back to the current bg (which is correct, so it ends up being a full coloured block).

Changing it to this fixes the issue:

"background": "parentBackground",
"leading_diamond": "<transparent,parentBackground>\uE0B0</>",

I'll see what I can do ;-)

thanhph111 commented 2 years ago

Sorry for picking a special example, let me take another one here:

{
    "blocks": [
        {
            "alignment": "left",
            "newline": false,
            "type": "prompt",
            "segments": [
                {
                    "type": "time",
                    "style": "diamond",
                    "leading_diamond": "\uE0B6",
                    "background": "red",
                    "foreground": "lightWhite"
                },
                {
                    "type": "session",
                    "style": "powerline",
                    "powerline_symbol": "\uE0B4",
                    "foreground": "parentForeground",
                    "background": "yellow",
                    "properties": {
                        "template": "{{ .ComputerName }}"
                    }
                },
                {
                    "type": "shell",
                    "style": "powerline",
                    "foreground": "parentForeground",
                    "background": "parentBackground",
                    "properties": {
                        "prefix": "● "
                    }
                },
                {
                    "type": "path",
                    "style": "powerline",
                    "powerline_symbol": "\uE0B4",
                    "foreground": "lightWhite",
                    "background": "blue"
                }
            ]
        }
    ]
}

And we will have:

image

As you said, we don't loop to expand values so only first parentForeground works, that's correct. However, the parentBackground doesn't seem to expand either. It lets the last symbol fall back to default background color. I don't know if it was intended or not.

Changing back to specific color works perfectly:

-                    "background": "parentBackground",
+                    "background": "yellow",

image

-                    "background": "parentBackground",
+                    "background": "green",

image

JanDeDobbeleer commented 2 years ago

@thanhph111 the last example has one thing which isn't supported and that's a grandparent. But I'm working on resolving the issue as we could in theory support it.

thanhph111 commented 2 years ago

Thanks a lot. I'm not familiar with Go so I'm not really useful with this, but if you need anything more I'd be happy to help. And yeah, the "grandparent" feature should be in another issue.

JanDeDobbeleer commented 2 years ago

@thanhph111 I fixed it, but it needs proper testing. This part of the codebase isn't as easy, but I was able to make it simpler in the process.

thanhph111 commented 2 years ago

Glad to hear that, thank you. BTW, just curious, I've seen a high frequency of releases, how do you decide which version to choose for your next release?

JanDeDobbeleer commented 2 years ago

Every change gets pushed, versions are generated automatically.

thanhph111 commented 2 years ago

So we aren't following semantic versioning?

JanDeDobbeleer commented 2 years ago

@thanhph111 yes we are, fully automated via conventional commits.

thanhph111 commented 2 years ago

@JanDeDobbeleer Does version 6.36.1 include this issue? Looks like it's still broken somehow.

image

JanDeDobbeleer commented 2 years ago

Yes it does:

image

In your sample the shell segment doesn't have a powerline_symbol so we obviously do not print anything. That was actually a bug, now we do it correctly.

thanhph111 commented 2 years ago

Sorry for disturbing you again. I try to reproduce this old settings on this new release style but no luck. Here my config:

{
    "blocks": [
        {
            "alignment": "left",
            "newline": false,
            "type": "prompt",
            "segments": [
                {
                    "type": "time",
                    "style": "diamond",
                    "leading_diamond": "\ue0b6",
                    "background": "red",
                    "foreground": "lightWhite"
                },
                {
                    "type": "session",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b4",
                    "foreground": "lightWhite",
                    "background": "yellow",
                    "properties": {
                        "template": "{{ .ComputerName }}"
                    }
                },
                {
                    "type": "shell",
                    "style": "powerline",
                    "foreground": "lightWhite",
                    "background": "yellow",
                    "properties": {
                        "prefix": "● "
                    }
                },
                {
                    "type": "envvar",
                    "style": "powerline",
                    "foreground": "lightWhite",
                    "background": "yellow",
                    "properties": {
                        "prefix": "",
                        "template": "\uf708",
                        "var_name": "NO_HISTORY"
                    }
                },
                {
                    "type": "path",
                    "style": "powerline",
                    "powerline_symbol": "\ue0b4",
                    "foreground": "lightWhite",
                    "background": "blue"
                }
            ]
        }
    ]
}

Here are the renders:

image

image

I have tried several configurations but none of them are the same as my old ones, they have an extra space between segments.

image

image

thanhph111 commented 2 years ago

@JanDeDobbeleer I saw the release, thank you very much, but it doesn't seem to change, do I have to rewrite the config or something?

image

But it's quite not important, I can live with 6.34.1 for a while, if you feel tired with this issue, we can fix it later, no need to hurry.

JanDeDobbeleer commented 2 years ago

I don't feel tired, I did fix it but maybe I did something stupid.

JanDeDobbeleer commented 2 years ago

@thanhph111 I just double checked and it is fixed on my end with 6.36.2, using the config you provided I get the following result:

image image
thanhph111 commented 2 years ago

Sorry for that, I've just realized I don't have to put powerline_symbol to followed segments anymore, that's amazing. Thanks a lot, man. You're brilliant.

github-actions[bot] commented 7 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.