JanDeDobbeleer / oh-my-posh

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

`overflow: hide` ignores length of right-aligned block #5220

Closed NikSays closed 5 days ago

NikSays commented 1 week ago

Code of Conduct

What happened?

I will use the attached theme as an example:

Expected behavior

When using overflow: hide, I expect right-aligned prompts to be printed only if everything fits.

Using my example:

+------------------------+
|LLLLLLLLLLLLL     RRRRRR| # width=24, everything is printed
+------------------------+

+-----------------------+
|LLLLLLLLLLLLL          | # width=23, not enough breathing room, right prompt is not printed
+-----------------------+

+------------+
|LLLLLLLLLLLL| # width=12, overflow case, only the last line is counted.
|L     RRRRRR|
+------------+

Current behavior

The right prompt is printed as long as the width of the terminal is more or equal to the length of the left prompt and the breathing room. The length of the right prompt is not accounted for.

Using my exapmle:

+------------------------+
|LLLLLLLLLLLLL     RRRRRR| # width=24, everything is printed
+------------------------+

+-------------------+
|LLLLLLLLLLLLLRRRRRR| # width=19, the right prompt is printed, even though no breathing room is left.
+-------------------+ # Why? Because leftPrompt+breathingRoom <= width. (13+5 <= 19)

+------------------+
|LLLLLLLLLLLLLRRRRR| # width=18, the right prompt is printed, even though it overflows to the next line.
|R                 | # Why? Because leftPrompt+breathingRoom <= width. (13+5 <= 18)
+------------------+

+-----------------+
|LLLLLLLLLLLLL    | # width=17, right prompt is hidden becaue 13+5 > 18.
+-----------------+

+------------+
|LLLLLLLLLLLL| # width=12, overflow case, only the last line is counted.
|L     RRRRRR|
+------------+

For type: rprompt, the behavior is similar, except it hides instead of overflowing to the next line when width=18.

Possible fix

Engine.canWriteRightBlock function could take length of the new block as an argument, and calculate the result as

canWrite := availableSpace-length >= promptBreathingRoom

Note: I'm not sure whether shells other than ZSH are affected.

Theme

I am using the following config to test this functionality:

# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json
version: 2
blocks:
  - type: prompt
    alignment: left
    segments:
      - type: text
        template: "LLLLLLLLLLLLL"
  - type: prompt
    overflow: hide
    alignment: right
    segments:
      - type: text
        template: "RRRRRR"

What OS are you seeing the problem on?

macOS

Which shell are you using?

zsh

Log output

Version: 21.20.2

Shell: zsh (5.9)

Prompt:

LLLLLLLLLLLLLRRRRRR

Segments:

ConsoleTitle(false)                       -   0 ms
Text(true)                                -   0 ms
Text(true)                                -   0 ms

Run duration: 4.375958ms

Cache path: ***/.cache/oh-my-posh

Config path: ***/.config/zsh/posh2.yaml

Logs:

[DEBUG] 03:22:11.251 os.go:Getenv:306 → NO DATA
[TRACE] 03:22:11.251 os.go:Getenv(OMP_CACHE_DIR) - 89.459µs
[DEBUG] 03:22:11.251 os.go:Getenv:306 → NO DATA
[TRACE] 03:22:11.251 os.go:Getenv(XDG_CACHE_HOME) - 2.416µs
[TRACE] 03:22:11.251 os_unix.go:CachePath() - 113.333µs
[DEBUG] 03:22:11.252 os.go:Getenv:306 → ***/.config/zsh/posh2.yaml
[TRACE] 03:22:11.252 os.go:Getenv(POSH_THEME) - 3.75µs
[DEBUG] 03:22:11.252 os_unix.go:Platform:87 → darwin
[TRACE] 03:22:11.252 os.go:resolveConfigPath() - 10.958µs
[TRACE] 03:22:11.252 os.go:Init() - 691.042µs
[TRACE] 03:22:11.252 os.go:Flags() - 42ns
[TRACE] 03:22:11.252 load.go:loadConfig() - 271.291µs
[TRACE] 03:22:11.252 os.go:Flags() - 41ns
[DEBUG] 03:22:11.252 debug.go:44 → Terminal shell: %s shell
[DEBUG] 03:22:11.252 debug.go:44 → Terminal program: %s Unknown
[DEBUG] 03:22:11.252 os.go:Getenv:306 → NO DATA
[TRACE] 03:22:11.252 os.go:Getenv(OMP_CACHE_DISABLED) - 1.875µs
[DEBUG] 03:22:11.252 os.go:Shell:581 → no shell name provided in flags, trying to detect it
[DEBUG] 03:22:11.252 os.go:Shell:589 → process name: zsh
[TRACE] 03:22:11.252 os.go:Shell() - 86.709µs
[DEBUG] 03:22:11.252 os.go:Getenv:306 → 5.9
[TRACE] 03:22:11.252 os.go:Getenv(POSH_SHELL_VERSION) - 2.041µs
[DEBUG] 03:22:11.252 debug.go:PrintDebug:23 → Segment: Title
[DEBUG] 03:22:11.252 text.go:Render:73 → Rendering template:
[DEBUG] 03:22:11.252 os.go:Getenv:306 → NO DATA
[TRACE] 03:22:11.252 os.go:Getenv(POSH_CURSOR_LINE) - 3.208µs
[DEBUG] 03:22:11.252 os.go:Getenv:306 → NO DATA
[TRACE] 03:22:11.252 os.go:Getenv(POSH_CURSOR_COLUMN) - 1.75µs
[TRACE] 03:22:11.252 os.go:Flags() - 0s
[TRACE] 03:22:11.252 os.go:Flags() - 0s
[TRACE] 03:22:11.252 os.go:Shell() - 83ns
[TRACE] 03:22:11.252 os.go:Shell() - 41ns
[TRACE] 03:22:11.252 os.go:Flags() - 83ns
[TRACE] 03:22:11.252 os.go:GOOS() - 41ns
[DEBUG] 03:22:11.252 os.go:Pwd:336 → ***
[TRACE] 03:22:11.252 os.go:Pwd() - 14.625µs
[TRACE] 03:22:11.252 os.go:GOOS() - 42ns
[DEBUG] 03:22:11.252 segment.go:SetEnabled:115 → Segment: Text
[TRACE] 03:22:11.252 os_unix.go:Root() - 416ns
[TRACE] 03:22:11.252 os.go:Shell() - 42ns
[TRACE] 03:22:11.252 os.go:StatusCodes() - 209ns
[DEBUG] 03:22:11.252 os_unix.go:IsWsl:35 → false
[TRACE] 03:22:11.252 os_unix.go:IsWsl() - 2.583µs
[DEBUG] 03:22:11.252 os.go:TemplateCache:779 → environment: [TERM=xterm-256color EDITOR=nvim LANG=en_US.UTF-8 COLORFGBG=15;0 LC_TERMINAL_VERSION=3.5.2 LC_TERMINAL=iTerm2 COLORTERM=truecolor SHELL=/bin/zsh POSH_THEME=***/.config/zsh/posh2.yaml POSH_SHELL_VERSION=5.9 POSH_PID=92687 POWERLINE_COMMAND=oh-my-posh POSH_PROMPT_COUNT=11 ZLE_RPROMPT_INDENT=0]
[TRACE] 03:22:11.252 os.go:Pwd() - 125ns
[DEBUG] 03:22:11.252 os_unix.go:IsWsl:35 → false
[TRACE] 03:22:11.252 os_unix.go:IsWsl() - 2.333µs
[TRACE] 03:22:11.252 os.go:GOOS() - 0s
[TRACE] 03:22:11.252 os.go:GOOS() - 42ns
[TRACE] 03:22:11.252 os.go:GOOS() - 42ns
[TRACE] 03:22:11.252 os.go:GOOS() - 0s
[TRACE] 03:22:11.252 os.go:GOOS() - 42ns
[DEBUG] 03:22:11.252 os.go:User:474 → ***
[TRACE] 03:22:11.252 os.go:User() - 2.417µs
[DEBUG] 03:22:11.252 os.go:Host:491 → ***
[TRACE] 03:22:11.253 os.go:Host() - 7.084µs
[TRACE] 03:22:11.253 os.go:GOOS() - 41ns
[DEBUG] 03:22:11.253 os.go:Getenv:306 → 2
[TRACE] 03:22:11.253 os.go:Getenv(SHLVL) - 2.792µs
[TRACE] 03:22:11.253 os.go:TemplateCache() - 93.25µs
[DEBUG] 03:22:11.253 text.go:Render:73 → Rendering template: LLLLLLLLLLLLL
[DEBUG] 03:22:11.253 text.go:Render:73 → Rendering template:
[TRACE] 03:22:11.253 os.go:Shell() - 42ns
[TRACE] 03:22:11.253 os.go:Shell() - 42ns
[TRACE] 03:22:11.253 os.go:Shell() - 41ns
[TRACE] 03:22:11.253 os.go:Shell() - 42ns
[TRACE] 03:22:11.253 os.go:Flags() - 42ns
[TRACE] 03:22:11.253 os.go:Pwd() - 83ns
[TRACE] 03:22:11.253 os.go:GOOS() - 42ns
[DEBUG] 03:22:11.253 segment.go:SetEnabled:115 → Segment: Text
[TRACE] 03:22:11.253 os.go:TemplateCache() - 83ns
[DEBUG] 03:22:11.253 text.go:Render:73 → Rendering template: RRRRRR
[DEBUG] 03:22:11.253 text.go:Render:73 → Rendering template:
[DEBUG] 03:22:11.256 os_unix.go:TerminalWidth:80 → terminal width: 18
[TRACE] 03:22:11.256 os_unix.go:TerminalWidth() - 2.989834ms
[TRACE] 03:22:11.256 os.go:Shell() - 83ns
[TRACE] 03:22:11.256 os.go:Shell() - 41ns
[TRACE] 03:22:11.256 os.go:Shell() - 42ns
[TRACE] 03:22:11.256 os.go:Shell() - 42ns
[TRACE] 03:22:11.256 os.go:Flags() - 41ns
[DEBUG] 03:22:11.256 os.go:Getenv:306 → NO DATA
[TRACE] 03:22:11.256 os.go:Getenv(OMP_CACHE_DIR) - 3.417µs
[DEBUG] 03:22:11.256 os.go:Getenv:306 → NO DATA
[TRACE] 03:22:11.256 os.go:Getenv(XDG_CACHE_HOME) - 1.958µs
[TRACE] 03:22:11.256 os_unix.go:CachePath() - 24.875µs
NikSays commented 1 week ago

An example of how this looks with a real theme:

posh01


posh02


posh03