Piping Text to Select-String Shows ANSI Escape Sequences Instead of Color #12899

Closed
opened 2026-01-31 03:28:22 +00:00 by claunia · 4 comments
Owner

Originally created by @chrisbehanna on GitHub (Mar 7, 2021).

Environment

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd] Windows 10 Enterprise 10.0.19042.0
Windows Terminal version (if applicable): 1.6.10571.0

Any other software? PowerShell Core 7.1.2

Steps to reproduce

git ls-remote | Select-String git_gc

Expected behavior

A listing of the matching remote branches, with the string "git_gc" highlighted in color

Actual behavior

ff0f34e411366ca6a25b7e94ff2df0a1827e3bc8 refs/heads/build/←[7mgit_gc←[0m

Originally created by @chrisbehanna on GitHub (Mar 7, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd] Windows 10 Enterprise 10.0.19042.0 Windows Terminal version (if applicable): 1.6.10571.0 Any other software? PowerShell Core 7.1.2 ``` # Steps to reproduce `git ls-remote | Select-String git_gc` # Expected behavior A listing of the matching remote branches, with the string "git_gc" highlighted in color # Actual behavior ff0f34e411366ca6a25b7e94ff2df0a1827e3bc8 refs/heads/build/←[7mgit_gc←[0m
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 03:28:22 +00:00
Author
Owner

@DHowett commented on GitHub (Mar 7, 2021):

This is because git is disabling ANSI coloring shortly after it launches, even when it is redirected. This is a long-standing Cygwin/msys2 bug.

@DHowett commented on GitHub (Mar 7, 2021): This is because git is disabling ANSI coloring shortly after it launches, even when it is redirected. This is a long-standing Cygwin/msys2 bug.
Author
Owner

@chrisbehanna commented on GitHub (Mar 24, 2021):

This is because git is disabling ANSI coloring shortly after it launches, even when it is redirected. This is a long-standing Cygwin/msys2 bug.

Then how does git log --graph --color --decorate apply color?

@chrisbehanna commented on GitHub (Mar 24, 2021): > This is because git is disabling ANSI coloring shortly after it launches, even when it is redirected. This is a long-standing Cygwin/msys2 bug. Then how does `git log --graph --color --decorate` apply color?
Author
Owner

@DHowett commented on GitHub (Mar 24, 2021):

So truthfully, it's a little more nuanced than that. There's a more detailed write-up here: https://github.com/microsoft/terminal/issues/4921#issuecomment-599135352

There's some combination of process entry/exit and mode transition that results in VT being disabled when it should be enabled when git or a subprocess exits after control has returned to something that required VT to be on. In the git log case, nobody appears to be exiting and reconfiguring the console.

@DHowett commented on GitHub (Mar 24, 2021): So truthfully, it's a little more nuanced than that. There's a more detailed write-up here: https://github.com/microsoft/terminal/issues/4921#issuecomment-599135352 There's some combination of process entry/exit and mode transition that results in VT being disabled when it should be enabled when git or a subprocess exits after control has returned to something that required VT to be on. In the `git log` case, nobody appears to be exiting and reconfiguring the console.
Author
Owner

@chrisbehanna commented on GitHub (Mar 24, 2021):

Thanks for the additional detail. For now, I'll just use Select-String -NoEmphasis when running git ls-remote to look for particular branches.

@chrisbehanna commented on GitHub (Mar 24, 2021): Thanks for the additional detail. For now, I'll just use `Select-String -NoEmphasis` when running `git ls-remote` to look for particular branches.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12899