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

Open
opened 2026-01-31 02:55:54 +00:00 by claunia · 0 comments
Owner

Originally created by @drichardson on GitHub (Dec 8, 2020).

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
Originally created by @drichardson on GitHub (Dec 8, 2020). 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 ```none 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 1. Set the prompt to be colored with ANSI escape codes: ``` function prompt { "`e[38;2;0;255;0mMyPrompt`e[0m>" } ``` 1. Run git log | less. Using full paths here: ```` & 'C:\Program Files\Git\bin\git.exe' log | & 'C:\Program Files\Git\usr\bin\less.exe' ```` 1. 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
claunia added the Resolution-ExternalNeeds-Tag-Fix labels 2026-01-31 02:55:54 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#11729