Skip to content

ANSI character codes displayed on prompt after piping output through less #8525

@drichardson

Description

@drichardson

After piping git log | less and then pressing Q to quit, the PowerShell prompt displayed in Windows Terminal shows character codes, instead of being colored.

Environment

Windows build number: 10.0.19042.0
Windows Terminal version (if applicable): 1.4.3243.0

Any other software?
PowerShell Core: 7.1.0

Steps to reproduce

  1. Open PowerShell Core in Windows Termianl

  2. Set the prompt to be colored with ANSI escape codes:

    function prompt { "`e[38;2;0;255;0mMyPrompt`e[0m>" }
    
  3. Run git log | less. Using full paths here:

    & 'C:\Program Files\Git\bin\git.exe' log | & 'C:\Program Files\Git\usr\bin\less.exe'
    
  4. Press Q to quit log.

Expected behavior

Should see "MyPrompt>" in green.

Actual behavior

Prompt looks like this:

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

Workaround

The problem does not occur if Control+C is used to quit less.exe instead of Q.

The problem does not occur if Out-Host -Paging is used instead of less.exe.

& 'C:\Program Files\Git\bin\git.exe' log | Out-Host -Paging

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-Tag-FixDoesn't match tag requirementsResolution-ExternalFor issues that are outside this codebase

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions