JanDeDobbeleer / oh-my-posh

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

Two-line prompt doesn't keep its styling in Nushell #4651

Closed youk closed 9 months ago

youk commented 9 months ago

Code of Conduct

What happened?

When superseded, two-line prompt loses its styling. For example, this is what happens upon entering pwd command:

image Happens both in Windows Terminal and Windows Console Host.

The same themes work fine with PowerShell:

image

Theme

Happens with any theme having two-line prompt, e.g. takuya.

What OS are you seeing the problem on?

Windows

Which shell are you using?

nu

Log output

Version: 19.8.2

Shell: nu (0.89.0)

Prompt:

╭─ nu  ~                                                                                                                                                                     00:59:24 
╰─❯

Segments:

ConsoleTitle(false)                       -   0 ms
Shell(true)                               -   0 ms
Root(false)                               -   0 ms
Path(true)                                -   2 ms
Git(false)                                -  13 ms
Node(false)                               -   0 ms
Time(true)                                -   0 ms
Text(true)                                -   0 ms
Status(true)                              -   0 ms

Run duration: 23.6631ms

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

Config path: C:\Users\test\AppData\Local\Programs\oh-my-posh\themes\takuya.omp.json

Logs:

[DEBUG] 01:01:55.404 shell.go:Getenv:399 → NO DATA
[TRACE] 01:01:55.404 shell.go:Getenv(TERM_PROGRAM) - 0s
[DEBUG] 01:01:55.404 shell.go:Getenv:399 → C:\Users\test\AppData\Local
[TRACE] 01:01:55.404 shell.go:Getenv(LOCALAPPDATA) - 0s
[TRACE] 01:01:55.405 shell_windows.go:CachePath() - 553.8µs
[DEBUG] 01:01:55.405 shell.go:Getenv:399 → C:\Users\test\AppData\Local/Programs/oh-my-posh/themes/takuya.omp.json
[TRACE] 01:01:55.405 shell.go:Getenv(POSH_THEME) - 0s
[DEBUG] 01:01:55.405 shell.go:Shell:662 → no shell name provided in flags, trying to detect it
[DEBUG] 01:01:55.411 shell.go:Shell:670 → process name: nu.exe
[TRACE] 01:01:55.411 shell.go:Shell() - 5.7722ms
[TRACE] 01:01:55.411 shell.go:resolveConfigPath() - 5.7722ms
[TRACE] 01:01:55.411 shell.go:Init() - 6.8754ms
[TRACE] 01:01:55.411 shell.go:Flags() - 0s
[TRACE] 01:01:55.412 config.go:loadConfig() - 561.8µs
[TRACE] 01:01:55.412 shell.go:Flags() - 0s
[DEBUG] 01:01:55.412 shell.go:Getenv:399 → NO DATA
[TRACE] 01:01:55.412 shell.go:Getenv(OMP_CACHE_DISABLED) - 0s
[TRACE] 01:01:55.412 shell_windows.go:WindowsRegistryKeyValue(HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor) - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[DEBUG] 01:01:55.412 shell_windows.go:WindowsRegistryKeyValue:215 → ColorizationColor(DWORD): 0xC4515C6B
[TRACE] 01:01:55.412 shell.go:Shell() - 0s
[DEBUG] 01:01:55.412 shell.go:Getenv:399 → 0.89.0
[TRACE] 01:01:55.412 shell.go:Getenv(POSH_SHELL_VERSION) - 0s
[DEBUG] 01:01:55.412 debug.go:PrintDebug:22 → Segment: Title
[DEBUG] 01:01:55.412 text.go:Render:70 → Rendering template: 
[DEBUG] 01:01:55.412 shell.go:Getenv:399 → NO DATA
[TRACE] 01:01:55.412 shell.go:Getenv(POSH_CURSOR_LINE) - 41.7µs
[DEBUG] 01:01:55.412 shell.go:Getenv:399 → NO DATA
[TRACE] 01:01:55.412 shell.go:Getenv(POSH_CURSOR_COLUMN) - 0s
[TRACE] 01:01:55.412 shell.go:Flags() - 0s
[TRACE] 01:01:55.412 shell.go:Flags() - 0s
[TRACE] 01:01:55.412 shell.go:Shell() - 0s
[TRACE] 01:01:55.412 shell.go:Shell() - 0s
[TRACE] 01:01:55.412 shell.go:Flags() - 0s
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[DEBUG] 01:01:55.412 shell.go:Pwd:429 → C:\Users\test
[TRACE] 01:01:55.412 shell.go:Pwd() - 0s
[DEBUG] 01:01:55.412 shell_windows.go:56 → C:\Users\test
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:Flags() - 0s
[TRACE] 01:01:55.412 shell.go:Pwd() - 0s
[DEBUG] 01:01:55.412 shell_windows.go:56 → C:\Users\test
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[DEBUG] 01:01:55.412 segment.go:SetEnabled:518 → Segment: Root
[TRACE] 01:01:55.412 shell_windows.go:Root() - 0s
[TRACE] 01:01:55.412 shell.go:Flags() - 0s
[TRACE] 01:01:55.412 shell.go:Pwd() - 0s
[DEBUG] 01:01:55.412 shell_windows.go:56 → C:\Users\test
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[TRACE] 01:01:55.412 shell.go:Flags() - 0s
[DEBUG] 01:01:55.412 segment.go:SetEnabled:518 → Segment: Shell
[TRACE] 01:01:55.412 shell.go:Pwd() - 0s
[DEBUG] 01:01:55.412 properties.go:GetKeyValueMap:46 → mapped_shell_names: map[]
[TRACE] 01:01:55.412 shell.go:Shell() - 0s
[TRACE] 01:01:55.412 shell.go:Flags() - 0s
[DEBUG] 01:01:55.412 shell_windows.go:56 → C:\Users\test
[TRACE] 01:01:55.412 shell.go:GOOS() - 0s
[DEBUG] 01:01:55.412 segment.go:SetEnabled:518 → Segment: Path
[TRACE] 01:01:55.412 shell_windows.go:Root() - 0s
[TRACE] 01:01:55.412 shell.go:Shell() - 0s
[TRACE] 01:01:55.412 shell.go:Shell() - 0s
[TRACE] 01:01:55.412 shell.go:StatusCodes() - 0s
[TRACE] 01:01:55.412 shell_windows.go:IsWsl() - 0s
[DEBUG] 01:01:55.413 properties.go:GetString:28 → 
[DEBUG] 01:01:55.413 properties.go:GetString:28 → 
[TRACE] 01:01:55.413 shell.go:Pwd() - 0s
[DEBUG] 01:01:55.413 shell_windows.go:56 → C:\Users\test
[DEBUG] 01:01:55.413 shell_windows.go:56 → C:\Users\test
[TRACE] 01:01:55.413 shell.go:GOOS() - 0s
[TRACE] 01:01:55.413 shell.go:GOOS() - 0s
[TRACE] 01:01:55.413 shell.go:GOOS() - 0s
[TRACE] 01:01:55.413 shell.go:GOOS() - 0s
[TRACE] 01:01:55.413 shell.go:GOOS() - 0s
[TRACE] 01:01:55.413 shell.go:GOOS() - 0s
[DEBUG] 01:01:55.413 shell.go:User:564 → test
[TRACE] 01:01:55.413 shell.go:GOOS() - 0s
[TRACE] 01:01:55.413 shell.go:User() - 0s
[DEBUG] 01:01:55.413 properties.go:GetString:28 → ~
[DEBUG] 01:01:55.413 properties.go:GetKeyValueMap:46 → mapped_locations: map[]
[TRACE] 01:01:55.413 shell.go:Host() - 0s
[TRACE] 01:01:55.413 shell.go:GOOS() - 0s
[TRACE] 01:01:55.413 shell.go:PathSeparator() - 0s
[DEBUG] 01:01:55.413 shell.go:Getenv:399 → NO DATA
[TRACE] 01:01:55.413 shell.go:Getenv(SHLVL) - 0s
[TRACE] 01:01:55.413 shell.go:TemplateCache() - 549.4µs
[TRACE] 01:01:55.413 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:PathSeparator() - 0s
[TRACE] 01:01:55.414 shell.go:PathSeparator() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:PathSeparator() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:PathSeparator() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:GOOS() - 0s
[TRACE] 01:01:55.414 shell.go:PathSeparator() - 0s
[TRACE] 01:01:55.414 shell.go:Pwd() - 0s
[TRACE] 01:01:55.414 shell_windows.go:IsWsl() - 0s
[TRACE] 01:01:55.414 shell.go:StackCount() - 0s
[DEBUG] 01:01:55.415 win32_windows.go:isWriteable:299 → not current user or in group
[DEBUG] 01:01:55.415 win32_windows.go:isWriteable:303 → current user is member of S-1-5-32-544
[DEBUG] 01:01:55.415 win32_windows.go:isWriteable:311 ↓
    WRITE_DAC
    WRITE_OWNER
    SYNCHRONIZE
    DELETE
    READ_CONTROL
[DEBUG] 01:01:55.415 win32_windows.go:isWriteable:313 → user has write access
[TRACE] 01:01:55.415 shell_windows.go:DirIsWritable() - 588.1µs
[TRACE] 01:01:55.415 shell.go:TemplateCache() - 0s
[DEBUG] 01:01:55.426 shell.go:CommandPath:615 → C:\Program Files\Git\cmd\git.exe
[TRACE] 01:01:55.426 shell.go:CommandPath(git.exe) - 13.3901ms
[TRACE] 01:01:55.426 shell.go:HasCommand(git.exe) - 13.3901ms
[TRACE] 01:01:55.426 shell.go:Pwd() - 0s
[ERROR] 01:01:55.426 shell.go:HasParentFilePath:758 → CreateFile .git: The system cannot find the file specified.
[TRACE] 01:01:55.426 shell.go:HasParentFilePath(.git) - 584.6µs
[DEBUG] 01:01:55.426 properties.go:GetBool:22 → fetch_bare_info: false
[DEBUG] 01:01:55.426 text.go:Render:70 → Rendering template:  {{ .Name }} 
[DEBUG] 01:01:55.426 text.go:Render:70 → Rendering template:  {{ .Path }} 
[TRACE] 01:01:55.427 shell.go:TemplateCache() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[TRACE] 01:01:55.427 shell.go:TemplateCache() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: diamond
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: diamond
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: powerline
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: powerline
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[TRACE] 01:01:55.427 shell.go:Flags() - 0s
[TRACE] 01:01:55.427 shell.go:Pwd() - 0s
[TRACE] 01:01:55.427 shell.go:Flags() - 0s
[DEBUG] 01:01:55.427 shell_windows.go:56 → C:\Users\test
[TRACE] 01:01:55.427 shell.go:GOOS() - 0s
[DEBUG] 01:01:55.427 segment.go:SetEnabled:518 → Segment: Time
[TRACE] 01:01:55.427 shell.go:Pwd() - 0s
[DEBUG] 01:01:55.427 properties.go:GetString:28 → 15:04:05
[TRACE] 01:01:55.427 shell.go:TemplateCache() - 0s
[DEBUG] 01:01:55.427 shell_windows.go:56 → C:\Users\test
[TRACE] 01:01:55.427 shell.go:GOOS() - 0s
[DEBUG] 01:01:55.427 segment.go:SetEnabled:518 → Segment: Node
[DEBUG] 01:01:55.427 properties.go:GetStringArray:52 → extensions: [*.js *.ts package.json .nvmrc pnpm-workspace.yaml .pnpmfile.cjs .npmrc .vue]
[DEBUG] 01:01:55.427 properties.go:GetStringArray:52 → folders: []
[DEBUG] 01:01:55.427 properties.go:GetBool:22 → home_enabled: false
[TRACE] 01:01:55.427 shell.go:Pwd() - 0s
[DEBUG] 01:01:55.427 shell_windows.go:56 → C:\Users\test
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template:   {{ .CurrentDate | date .Format }} 
[TRACE] 01:01:55.427 shell.go:TemplateCache() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: diamond
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: diamond
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[DEBUG] 01:01:55.427 shell_windows.go:TerminalWidth:109 → terminal width: 188
[TRACE] 01:01:55.427 shell_windows.go:TerminalWidth() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[TRACE] 01:01:55.427 shell.go:Flags() - 0s
[DEBUG] 01:01:55.427 properties.go:GetString:28 → {{ .Code }}
[TRACE] 01:01:55.427 shell.go:Pwd() - 0s
[DEBUG] 01:01:55.427 shell_windows.go:56 → C:\Users\test
[TRACE] 01:01:55.427 shell.go:GOOS() - 0s
[DEBUG] 01:01:55.427 segment.go:SetEnabled:518 → Segment: Status
[TRACE] 01:01:55.427 shell.go:StatusCodes() - 0s
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: {{ .Code }}
[TRACE] 01:01:55.427 shell.go:Flags() - 0s
[TRACE] 01:01:55.427 shell.go:Pwd() - 0s
[DEBUG] 01:01:55.427 shell_windows.go:56 → C:\Users\test
[TRACE] 01:01:55.427 shell.go:GOOS() - 0s
[DEBUG] 01:01:55.427 segment.go:SetEnabled:518 → Segment: Text
[TRACE] 01:01:55.427 shell.go:TemplateCache() - 0s
[TRACE] 01:01:55.427 shell.go:TemplateCache() - 0s
[DEBUG] 01:01:55.427 properties.go:GetBool:22 → always_enabled: true
[TRACE] 01:01:55.427 shell.go:TemplateCache() - 0s
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: ❯ 
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: ╰─
[TRACE] 01:01:55.427 shell.go:Shell() - 0s
[DEBUG] 01:01:55.427 shell.go:Getenv:399 → NO DATA
[TRACE] 01:01:55.427 shell.go:Getenv(TERM_PROGRAM) - 0s
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: plain
[DEBUG] 01:01:55.427 text.go:Render:70 → Rendering template: {{ if gt .Code 0 }}#ef5350{{ end }}
[TRACE] 01:01:55.427 shell.go:TemplateCache() - 0s
[DEBUG] 01:01:55.428 text.go:Render:70 → Rendering template: plain
[TRACE] 01:01:55.428 shell.go:Shell() - 0s
[TRACE] 01:01:55.428 shell.go:Shell() - 0s
[TRACE] 01:01:55.428 shell.go:Shell() - 0s
[TRACE] 01:01:55.428 shell.go:Shell() - 0s
[DEBUG] 01:01:55.428 shell.go:Getenv:399 → C:\Users\test\AppData\Local
[TRACE] 01:01:55.428 shell.go:Getenv(LOCALAPPDATA) - 0s
[TRACE] 01:01:55.428 shell_windows.go:CachePath() - 79.1µs
[TRACE] 01:01:55.428 shell.go:Flags() - 0s
youk commented 9 months ago

I dug into the documentation and the behavior looks like that of a transient prompt. I checked the init script in use and it unconditionally sets $env.TRANSIENT_PROMPT_COMMAND (by if "true" == "true"). From what I am reading in Transient prompt this should be theme-dependent, no?

JanDeDobbeleer commented 9 months ago

@youk that's set when there's a transient prompt in the configuration, if I use the theme you use, this is what the script looks like:

$ oh-my-posh init nu --print --config /Users/JDedob/homebrew/opt/oh-my-posh/themes/takuya.omp.json
$env.config = ($env.config | upsert render_right_prompt_on_last_line true)

$env.POWERLINE_COMMAND = 'oh-my-posh'
$env.POSH_THEME = "/Users/JDedob/homebrew/opt/oh-my-posh/themes/takuya.omp.json"
$env.PROMPT_INDICATOR = ""
$env.POSH_PID = (random uuid)
$env.POSH_SHELL_VERSION = (version | get version)

def posh_cmd_duration [] {
    # We have to do this because the initial value of `$env.CMD_DURATION_MS` is always `0823`,
    # which is an official setting.
    # See https://github.com/nushell/nushell/discussions/6402#discussioncomment-3466687.
    if $env.CMD_DURATION_MS == "0823" { 0 } else { $env.CMD_DURATION_MS }
}

def posh_width [] {
    (term size).columns | into string
}

# PROMPTS
$env.PROMPT_MULTILINE_INDICATOR = (^"/Users/JDedob/homebrew/bin/oh-my-posh" print secondary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)")

$env.PROMPT_COMMAND = { ||
    # hack to set the cursor line to 1 when the user clears the screen
    # this obviously isn't bulletproof, but it's a start
    let clear = (history | last 1 | get 0.command) == "clear"

    ^"/Users/JDedob/homebrew/bin/oh-my-posh" print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=(posh_cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=(posh_width)" $"--cleared=($clear)"
}

$env.PROMPT_COMMAND_RIGHT = { ||    
    ^"/Users/JDedob/homebrew/bin/oh-my-posh" print right $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=(posh_cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=(posh_width)"
}

if "false" == "true" {
    $env.TRANSIENT_PROMPT_COMMAND = { ||
        ^"/Users/JDedob/homebrew/bin/oh-my-posh" print transient $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=(posh_cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=(posh_width)"
    }
}

if "false" == "true" {
    echo ""
}

You can see this isn't activated. The only way it can "stay" activated, is when you initialise with the default config, or one that also has a transient prompt, and then set a configuration without one as those functions are still set. That will also result in the prompt you see, as that's the default transient prompt.

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