Oh-my-posh3: Icons don't render in prompt function, but do directly from oh-my-posh.exe

Created on 19 Oct 2020  路  3Comments  路  Source: JanDeDobbeleer/oh-my-posh3

Description

Character encoding is broken in prompt function, but not when I call oh-my-posh directly.

Environment

  • Oh my Posh version: 3.17
  • Theme: Custom (same behavior with default theme)
  • Operating System: Win 10 2004
  • Shell: PowerShell 7.0.3
  • Terminal: Windows Terminal 1.3.2651.0

Steps to Reproduce

Prompt doesn't render icons, but if you run oh-my-posh directly with the same config it renders as expected.
image

Prompt function script:

    [ScriptBlock]$Prompt = {

        $realLASTEXITCODE = $global:LASTEXITCODE
        if ([string]::IsNullOrEmpty($realLASTEXITCODE) ) { $realLASTEXITCODE = 0 }
        & oh-my-posh -config C:\Users\chunt\.ohmyposh.json -error $realLASTEXITCODE -pwd $PWD.Path
        $global:LASTEXITCODE = $realLASTEXITCODE
        Remove-Variable realLASTEXITCODE -Confirm:$false
      }
      Set-Item -Path Function:\prompt -Value $Prompt -Force
}

Most helpful comment

Try adding

[console]::OutputEncoding = New-Object System.Text.UTF8Encoding

before your [ScriptBlock]

All 3 comments

Try adding

[console]::OutputEncoding = New-Object System.Text.UTF8Encoding

before your [ScriptBlock]

@nwykes is right, the encoding in the prompt function is different (respects the code page set by Powershell rather than the executable). The PowerShell module adds this for you, I'll update the docs with that context too.

I thought Powershell finally standardized on UTF8. Anyway, that worked. Thanks!

Was this page helpful?
0 / 5 - 0 ratings