Skip to content

InvokePrompt breaks with a prompt that prints unicode characters #2866

Open
@segevfiner

Description

@segevfiner

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

  1. Install a prompt function that writes directly to the console and uses Unicode characters. (e.g. https://starship.rs/)
  2. Run [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
  3. 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:
image

Actual behavior

The prompt is rendered incorrectly:
image

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.

References

kelleyma49/PSFzf#71

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-StabilityLabel for tracking stability IssuesIssue-BugIt either shouldn't be doing this or needs an investigation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions