Skip to content

ANSI escape codes in prompt incorrectly rendered in some cases #14360

@drichardson

Description

@drichardson

After a pipeline that contains a some programs from Git for Windows (e.g., cat.exe), ANSI escape codes in the prompt are incorrectly rendered.

Steps to reproduce

  1. Setup a prompt function that sets the prompt to MyPrompt in green.
  2. Run a command that pipes data through cat.exe from Git for Windows (problem also occurs with other programs as well, but cat.exe is the simplest).
doug> function prompt { $ESC = [char]27; "$ESC[38;2;0;255;0mMyPrompt$ESC[0m>" }
MyPrompt>echo "n"| & 'C:\Program Files\Git\usr\bin\cat.exe'
n
←[38;2;0;255;0mMyPrompt←[0m>

Expected behavior

MyPrompt should be green.

MyPrompt>

Actual behavior

The prompt is white with the color codes visible.

←[38;2;0;255;0mMyPrompt←[0m>

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Additional Notes

This problem does not occur in Windows Powershell.

This problem occurs with Powershell Core 7.1.0 both running in Windows Terminal and running PowerShell 7 directly.

This issue was originally reported to microsoft/terminal#8525, but some investigation led me to believe the problem is in PowerShell Core, not Windows Terminal (see details of that bug for more information).

Metadata

Metadata

Assignees

Labels

Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aWG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions