Description
Environment
PS version: 7.1.4
PSReadline version: 2.1.0
os: 10.0.19041.1 (WinBuild.160101.0800)
PS file version: 7.1.4.0
HostName: ConsoleHost (Windows Terminal)
BufferWidth: 120
BufferHeight: 30
Exception report
N/A
Steps to reproduce
- Install a prompt function that writes directly to the console and uses Unicode characters. (e.g. https://starship.rs/)
- Run
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
- The prompt will be output garbled with question marks in place of Unicode characters.
This function is used by other projects, such as PSFzf to re-render the prompt in cases where this is necessary.
Expected behavior
The prompt is rendered correctly:
Actual behavior
The prompt is rendered incorrectly:
Analysis
It appears the InvokePrompt
is using GetPrompt
, buffering the prompt to a string and then writing it to the console by itself. But because the default [Console]::OutputEncoding
is not UTF8, this breaks, which the prompt function handles when it gets to write to the console directly by itself under normal circumstances.
A workaround can be to set [Console]::OutputEncoding
to [Text.Encoding]::UTF8
, which does make this work, yet I'm unsure what side effects this might have on other stuff in PowerShell that will try to output to the console, or maybe that should have been the default but isn't for some reason?
If this shouldn't be changed, then maybe PSReadline should set this temporarily while printing the prompt to the console? Or alternatively, re-implement InvokePrompt
in a way that won't require it to buffer the prompt string.