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

java segment causes negative horizontal offset #1691

Closed GethDeeo closed 2 years ago

GethDeeo commented 2 years ago

Code of Conduct

What happened?

When java segment gets enabled, it causes a significant amount of negative offset added to itself and the rest of segments on that line. PowerShell 7.2.0 Terminal 1.11.3471.0

Screenshot 2022-02-04 195348

Theme

version: 1
$schema: https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json
final_space: true
console_title: true
console_title_style: template
console_title_template: "{{if .Root}}# {{end}}{{.UserName}}@{{.HostName}}: {{.Folder}}"
blocks:
  # 1st line left
  - type: prompt
    alignment: left
    segments:
      - type: session
        style: powerline
        powerline_symbol: "\ue0c6"
        background: darkGray
        properties:
          template: "\u2800{{if .SSHSession}}\uf817 {{end}}{{if .Root}}<red>\uf234{{else}}<green>\uf007{{end}} <b>{{.UserName}}</b></>@{{.HostName}}"
      - type: os
        style: powerline
        powerline_symbol: "\ue0c6"
        foreground: transparent
        background: blue
        properties:
          template: "\u2800{{if .WSL}}\ue70f/{{end}}{{.Icon}} "
          windows: "\ue70f"
      - type: path
        style: powerline
        powerline_symbol: "\ue0c6"
        foreground: transparent
        background: yellow
        properties:
          template: "\u2800\uf74a {{path .Path .Location}} "
          style: agnoster_full
      - type: git
        style: powerline
        powerline_symbol: "\ue0c6"
        foreground_templates:
          - "{{if or (.Working.Changed) (.Staging.Changed)}}lightYellow{{end}}"
          - "{{if lt 0 .Behind}}lightCyan{{end}}"
          - "{{if lt 0 .Ahead}}lightMagenta{{end}}"
        background: "#2f2f2f"
        properties:
          template: "\u2800{{.UpstreamIcon}}{{.HEAD}}{{.BranchStatus}}{{if .Working.Changed}} \uf044 <lightRed>{{.Working.String}}</>{{end}}{{if and (.Working.Changed) (.Staging.Changed)}} |{{end}}{{if .Staging.Changed}} \uf046 <lightGreen>{{.Staging.String}}</>{{end}}{{if lt 0 .StashCount}} \uf692 {{.StashCount}}{{end}}{{if lt 0 .WorktreeCount}} \uf1bb {{.WorktreeCount}}{{end}} "
          fetch_status: true
          fetch_stash_count: true
          fetch_worktree_count: true
          fetch_upstream_icon: true
  # 1st line right
  - type: prompt
    alignment: right
    segments:
      - type: java
        style: powerline
        powerline_symbol: "\ue0c6"
        foreground: transparent
        background: yellow
        properties:
          template: "{{if .Env.JAVA_HOME}}\u2800\ue256 {{if .Error}}{{.Error}}{{else}}{{path .Full .Env.JAVA_HOME}}{{end}} {{end}}"
          display_mode: always
      - type: python
        style: powerline
        powerline_symbol: "\ue0c6"
        foreground: transparent
        background: yellow
        properties:
          template: "\u2800\ue235 {{if .Error}}{{.Error}}{{else}}{{if .Venv}}{{.Venv}} {{end}}{{.Full}}{{end}} "
      - type: shell
        style: powerline
        powerline_symbol: "\ue0c6"
        foreground: transparent
        background: blue
        properties:
          template: "\u2800\uf68c {{.Name}} "
      - type: time
        style: powerline
        powerline_symbol: "\ue0c6"
        background: darkGray
        properties:
          template: "\u2800\uf64f {{.CurrentDate | date .Format}} "
  # 2nd line left
  - type: prompt
    newline: true
    alignment: left
    segments:
      - type: text
        style: plain
        properties:
          template: "{{if .Root}}<red>#{{else}}<green>${{end}}</>"
  # 2nd line right
  - type: rprompt
    segments:
      - type: exit
        style: plain
        properties:
          template: " \uf705 {{if eq 0 .Code}}<green>\uf632</>{{else}}<red>\uf06a {{.Meaning}}</>{{end}} "
          always_enabled: true
      - type: executiontime
        style: plain
        properties:
          template: "<red>\ue0c3</>  \uf650 {{.FormattedMs}} <red>\ue0c1</> "

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Version: 7.8.4

Segments:

ConsoleTitle(true)   -   0 ms -
session(true)        -   0 ms - ⠀ geth@log-geth
os(true)             -   0 ms - ⠀
path(true)           -   0 ms - ⠀ ~\develop
git(false)           -   3 ms -
java(true)           - 198 ms - ⠀ 17.0.2
python(false)        -   0 ms -
shell(true)          -   0 ms - ⠀ pwsh
time(true)           -   0 ms - ⠀ 19:56:28
text(true)           -   0 ms - $
exit(true)           -   1 ms -    1337
executiontime(true)  -   0 ms -    9.001s 

Run duration: 204.3312ms

Cache path: C:\Users\geth\AppData\Local/oh-my-posh

Logs:

2022/02/04 19:56:28 Args duration: 0s, args:
2022/02/04 19:56:28 Args duration: 0s, args:
2022/02/04 19:56:28 Args duration: 0s, args:
2022/02/04 19:56:28 Shell duration: 0s, args:
2022/02/04 19:56:28 debug: Getenv

2022/02/04 19:56:28 Getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/02/04 19:56:28 Root duration: 0s, args:
2022/02/04 19:56:28 Shell duration: 0s, args:
2022/02/04 19:56:28 ErrorCode duration: 0s, args:
2022/02/04 19:56:28 IsWsl duration: 0s, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 User duration: 0s, args:
2022/02/04 19:56:28 Host duration: 0s, args:
2022/02/04 19:56:28 GOOS duration: 0s, args:
2022/02/04 19:56:28 TemplateCache duration: 600.7µs, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 debug: Getenv

2022/02/04 19:56:28 Getenv duration: 0s, args: SSH_CONNECTION
2022/02/04 19:56:28 debug: Getenv

2022/02/04 19:56:28 Getenv duration: 0s, args: SSH_CLIENT
2022/02/04 19:56:28 TemplateCache duration: 0s, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 GOOS duration: 0s, args:
2022/02/04 19:56:28 TemplateCache duration: 0s, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 Args duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 GOOS duration: 0s, args:
2022/02/04 19:56:28 GOOS duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 PathSeperator duration: 0s, args:
2022/02/04 19:56:28 GOOS duration: 0s, args:
2022/02/04 19:56:28 IsWsl duration: 0s, args:
2022/02/04 19:56:28 StackCount duration: 0s, args:
2022/02/04 19:56:28 TemplateCache duration: 0s, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 GOOS duration: 0s, args:
2022/02/04 19:56:28 HasCommand duration: 3.2834ms, args: git.exe
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 error: HasParentFilePath
CreateFile C:\.git: The system cannot find the file specified.
2022/02/04 19:56:28 HasParentFilePath duration: 0s, args: .git
2022/02/04 19:56:28 debug: Getenv
C:\Program Files\Amazon Corretto\jdk17.0.2_8
2022/02/04 19:56:28 Getenv duration: 0s, args: JAVA_HOME
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 HasCommand duration: 0s, args: C:\Program Files\Amazon Corretto\jdk17.0.2_8/bin/java
2022/02/04 19:56:28 debug: RunCommand
OpenJDK 64-Bit Server VM (17.0.2+8-LTS) for windows-amd64 JRE (17.0.2+8-LTS), built on Jan 17 2022 05:07:39 by "Administrator" with MS VC++ 15.9 (VS2017)
2022/02/04 19:56:28 RunCommand duration: 197.7441ms, args: C:\Program Files\Amazon Corretto\jdk17.0.2_8/bin/java -Xinternalversion
2022/02/04 19:56:28 TemplateCache duration: 0s, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 debug: Getenv

2022/02/04 19:56:28 Getenv duration: 0s, args: VIRTUAL_ENV
2022/02/04 19:56:28 debug: Getenv

2022/02/04 19:56:28 Getenv duration: 0s, args: CONDA_ENV_PATH
2022/02/04 19:56:28 debug: Getenv

2022/02/04 19:56:28 Getenv duration: 0s, args: CONDA_DEFAULT_ENV
2022/02/04 19:56:28 debug: Getenv

2022/02/04 19:56:28 Getenv duration: 0s, args: PYENV_VERSION
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 Shell duration: 0s, args:
2022/02/04 19:56:28 TemplateCache duration: 0s, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 TemplateCache duration: 0s, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 TemplateCache duration: 0s, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 ErrorCode duration: 0s, args:
2022/02/04 19:56:28 TemplateCache duration: 0s, args:
2022/02/04 19:56:28 debug: Pwd
C:\Users\geth\develop
2022/02/04 19:56:28 Pwd duration: 0s, args:
2022/02/04 19:56:28 debug: Home
C:\Users\geth
2022/02/04 19:56:28 ExecutionTime duration: 0s, args:
2022/02/04 19:56:28 TemplateCache duration: 0s, args:
2022/02/04 19:56:28 debug: Getenv
C:\Users\geth\AppData\Local
2022/02/04 19:56:28 Getenv duration: 0s, args: LOCALAPPDATA
2022/02/04 19:56:28 CachePath duration: 0s, args:
JanDeDobbeleer commented 2 years ago

@GethDeeo that's weird. Could it be some output has ANSI characters? What happens when you only add the icon and not the version information?

GethDeeo commented 2 years ago

This works: {{.Full}} This works: {{.Env.JAVA_HOME}} This causes the weird output: {{path .Full .Env.JAVA_HOME}} (the generated link itself is fine)

GethDeeo commented 2 years ago

@JanDeDobbeleer This is indeed fixed on Windows since your commit. However, I'm now using oh-my-posh on WSL and other linux environments too with the exact same theme posted here, and the problem has been resurfaced. The symptoms are exactly as I've described last time, only the size of the weird empty space is smaller this time (~10 characters).

I know the path helper function does not create clickable hyperlinks in these environments, but I would like to use the exact same theme across platforms.

$ oh-my-posh --version
7.57.0
JanDeDobbeleer commented 2 years ago

@GethDeeo which shell? Because I know the culprit ;-)

GethDeeo commented 2 years ago

It would be bash, if I'm not mistaken (ubuntu 20.04).

$ bash --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
JanDeDobbeleer commented 2 years ago

@GethDeeo if you don't know for sure, oh-my-posh get shell will tell you.

GethDeeo commented 2 years ago

bash it is :)

JanDeDobbeleer commented 2 years ago

@GethDeeo I found the issue, fixed it and identified another one. I'll push a fix somewhere tomorrow.

JanDeDobbeleer commented 2 years ago

@GethDeeo I just pushed a new version. If you would be so kind. It seems to now calculate the correct prompt width.

GethDeeo commented 2 years ago

To me it seems to be fixed. Thanks!

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