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

Unexpected behavior when using multiple segments of the same type #3268

Closed NoF0rte closed 1 year ago

NoF0rte commented 1 year ago

Code of Conduct

What happened?

There seems to be some weird unexpected behavior when using multiple segments of the same type. With the provided config, this is what the prompt should look like image

Using oh-my-posh compiled from the latest commit (a3ef56f7fad99b001f3d0ced7b1e5b3a60131915), the prompt can look like the following screenshots image

image

image

Playing around with the code myself, I found the issue comes from commit 04bfb2eef16818424881a3426de87f24f8ac79d5. It seems like since there are now global instances of each segment type's SegmentWriter, using multiple of the same segment type can result in unexpected behavior. Reverting the mapSegmentWithWriter function in src/engine/segment.go so that it creates the SegmentWriter map every time it is called, fixes the issue.

Theme

{
  "version": 2,
  "final_space": true,
  "blocks": [
    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "path",
          "style": "diamond",
          "powerline_symbol": "\ue0b0",
          "foreground": "#ffffff",
          "background": "#0087af",
          "leading_diamond": "\ue0b6",
          "trailing_diamond": "\ue0b0",
          "template": "{{ if hasPrefix \"~\" .Path }} \uf015 {{end}}",
          "properties": {
            "home_icon": "~"
          }
        },
        {
          "type": "path",
          "style": "powerline",
          "powerline_symbol": "\ue0b4",
          "foreground": "#A7A7A7",
          "background": "#3a3a3a",
          "template": "{{if or (ne .Path \"/\") (eq .Location \"/\")}} {{ .Path }} {{end}}",
          "properties": {
            "folder_separator_icon": " \ue0b1 ",
            "home_icon": "/",
            "max_depth": 2,
            "style": "agnoster_short"
          }
        }
      ]
    }
  ]
}

What OS are you seeing the problem on?

Linux

Which shell are you using?

zsh

Log output

Version: development

Segments:

ConsoleTitle(false) -   0 ms - 
path(true)  -   5 ms -   
path(true)  -   2 ms -  opt  oh-my-posh 

Run duration: 10.348504ms

Cache path: /home/kali/.cache/oh-my-posh

Config path: /home/kali/oh-my-posh.json

Logs:

2022/12/29 11:18:00 Getenv

2022/12/29 11:18:00 Getenv: 34.3µs, args: XDG_CACHE_HOME
2022/12/29 11:18:00 CachePath: 84.4µs
2022/12/29 11:18:00 Getenv
/home/kali/oh-my-posh.json
2022/12/29 11:18:00 Getenv: 65.3µs, args: POSH_THEME
2022/12/29 11:18:00 resolveConfigPath: 102.4µs
2022/12/29 11:18:00 Init: 1.392401ms
2022/12/29 11:18:00 Flags: 6.5µs
2022/12/29 11:18:00 config.loadConfig: 598.7µs
2022/12/29 11:18:00 Flags: 6.5µs
2022/12/29 11:18:00 Getenv

2022/12/29 11:18:00 Getenv: 21.4µs, args: OMP_CACHE_DISABLED
2022/12/29 11:18:00 Flags: 7.3µs
2022/12/29 11:18:00 GOOS: 6.3µs
2022/12/29 11:18:00 Pwd
/home/kali/opt/oh-my-posh
2022/12/29 11:18:00 Pwd: 65.4µs
2022/12/29 11:18:00 GOOS: 6.4µs
2022/12/29 11:18:00 Pwd
/home/kali/opt/oh-my-posh
2022/12/29 11:18:00 Pwd: 20.9µs
2022/12/29 11:18:00 Shell
process name: zsh
2022/12/29 11:18:00 Shell: 2.418901ms
2022/12/29 11:18:00 Shell: 6.8µs
2022/12/29 11:18:00 GOOS: 6.9µs
2022/12/29 11:18:00 PathSeparator: 7.8µs
2022/12/29 11:18:00 GOOS: 6.6µs
2022/12/29 11:18:00 GOOS: 6.7µs
2022/12/29 11:18:00 GOOS: 7µs
2022/12/29 11:18:00 GOOS: 6.8µs
2022/12/29 11:18:00 PathSeparator: 6.5µs
2022/12/29 11:18:00 PathSeparator: 6.9µs
2022/12/29 11:18:00 GOOS: 6.6µs
2022/12/29 11:18:00 GOOS: 6.9µs
2022/12/29 11:18:00 PathSeparator: 6.8µs
2022/12/29 11:18:00 GOOS: 6.2µs
2022/12/29 11:18:00 GOOS: 6.1µs
2022/12/29 11:18:00 PathSeparator: 5.9µs
2022/12/29 11:18:00 GOOS: 5.9µs
2022/12/29 11:18:00 GOOS: 5.9µs
2022/12/29 11:18:00 PathSeparator: 6µs
2022/12/29 11:18:00 PathSeparator: 5.9µs
2022/12/29 11:18:00 PathSeparator: 5.9µs
2022/12/29 11:18:00 PathSeparator: 5.899µs
2022/12/29 11:18:00 PathSeparator: 5.899µs
2022/12/29 11:18:00 Pwd
/home/kali/opt/oh-my-posh
2022/12/29 11:18:00 Pwd: 19.9µs
2022/12/29 11:18:00 Getenv

2022/12/29 11:18:00 Getenv: 22.3µs, args: WSL_DISTRO_NAME
2022/12/29 11:18:00 IsWsl: 55.2µs
2022/12/29 11:18:00 StackCount: 6µs
2022/12/29 11:18:00 DirIsWritable: 13.901µs, args: /home/kali/opt/oh-my-posh
2022/12/29 11:18:00 Root: 7.4µs
2022/12/29 11:18:00 Shell: 6.2µs
2022/12/29 11:18:00 ErrorCode: 6.1µs
2022/12/29 11:18:00 Getenv

2022/12/29 11:18:00 Getenv: 19.3µs, args: WSL_DISTRO_NAME
2022/12/29 11:18:00 IsWsl: 50.599µs
2022/12/29 11:18:00 Pwd
/home/kali/opt/oh-my-posh
2022/12/29 11:18:00 Pwd: 19.8µs
2022/12/29 11:18:00 GOOS: 6µs
2022/12/29 11:18:00 GOOS: 6µs
2022/12/29 11:18:00 GOOS: 5.9µs
2022/12/29 11:18:00 GOOS: 6.2µs
2022/12/29 11:18:00 GOOS: 6.1µs
2022/12/29 11:18:00 GOOS: 6µs
2022/12/29 11:18:00 GOOS: 6µs
2022/12/29 11:18:00 GOOS: 5.9µs
2022/12/29 11:18:00 GOOS: 5.9µs
2022/12/29 11:18:00 GOOS: 6µs
2022/12/29 11:18:00 GOOS: 6µs
2022/12/29 11:18:00 GOOS: 6µs
2022/12/29 11:18:00 User
kali
2022/12/29 11:18:00 User: 20.1µs
2022/12/29 11:18:00 Host
kali
2022/12/29 11:18:00 Host: 22.2µs
2022/12/29 11:18:00 GOOS: 6.1µs
2022/12/29 11:18:00 TemplateCache: 6µs
2022/12/29 11:18:00 TemplateCache: 6.2µs
2022/12/29 11:18:00 Shell: 6.701µs
2022/12/29 11:18:00 Pwd
/home/kali/opt/oh-my-posh
2022/12/29 11:18:00 Pwd: 23.201µs
2022/12/29 11:18:00 GOOS: 6.5µs
2022/12/29 11:18:00 Pwd
/home/kali/opt/oh-my-posh
2022/12/29 11:18:00 Pwd: 24.2µs
2022/12/29 11:18:00 Shell: 6.6µs
2022/12/29 11:18:00 Shell: 6.5µs
2022/12/29 11:18:00 GOOS: 6.5µs
2022/12/29 11:18:00 PathSeparator: 6.5µs
2022/12/29 11:18:00 GOOS: 6.3µs
2022/12/29 11:18:00 GOOS: 6.3µs
2022/12/29 11:18:00 GOOS: 6.799µs
2022/12/29 11:18:00 GOOS: 6.4µs
2022/12/29 11:18:00 PathSeparator: 6.4µs
2022/12/29 11:18:00 PathSeparator: 6.3µs
2022/12/29 11:18:00 GOOS: 6.2µs
2022/12/29 11:18:00 GOOS: 6.4µs
2022/12/29 11:18:00 PathSeparator: 6.4µs
2022/12/29 11:18:00 GOOS: 6.5µs
2022/12/29 11:18:00 GOOS: 6.3µs
2022/12/29 11:18:00 PathSeparator: 6.4µs
2022/12/29 11:18:00 GOOS: 6.1µs
2022/12/29 11:18:00 GOOS: 6.1µs
2022/12/29 11:18:00 PathSeparator: 6.3µs
2022/12/29 11:18:00 PathSeparator: 6.3µs
2022/12/29 11:18:00 PathSeparator: 6.1µs
2022/12/29 11:18:00 PathSeparator: 6.2µs
2022/12/29 11:18:00 PathSeparator: 6.3µs
2022/12/29 11:18:00 PathSeparator: 6.1µs
2022/12/29 11:18:00 PathSeparator: 6.2µs
2022/12/29 11:18:00 Pwd
/home/kali/opt/oh-my-posh
2022/12/29 11:18:00 Pwd: 20.1µs
2022/12/29 11:18:00 Getenv

2022/12/29 11:18:00 Getenv: 21.8µs, args: WSL_DISTRO_NAME
2022/12/29 11:18:00 IsWsl: 55.7µs
2022/12/29 11:18:00 StackCount: 6.6µs
2022/12/29 11:18:00 DirIsWritable: 22.4µs, args: /home/kali/opt/oh-my-posh
2022/12/29 11:18:00 TemplateCache: 6.5µs
2022/12/29 11:18:00 TemplateCache: 6.8µs
2022/12/29 11:18:00 Shell: 6.9µs
2022/12/29 11:18:00 Getenv

2022/12/29 11:18:00 Getenv: 24.399µs, args: XDG_CACHE_HOME
2022/12/29 11:18:00 CachePath: 336.299µs
2022/12/29 11:18:00 Flags: 27.601µs
JanDeDobbeleer commented 1 year ago

@NoF0rte can you create a PR for that small revert? Would be super amazing 🙏🏻

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.