Color Escape Codes displayed incorrectly #12761

Open
opened 2026-01-31 03:24:17 +00:00 by claunia · 11 comments
Owner

Originally created by @derekgreer on GitHub (Mar 1, 2021).

Originally assigned to: @DHowett on GitHub.

The problem:

###Microsoft Terminal with errors:
image

Git Bash Terminal

image

Cmder Terminal

image

Same behavior with Microsoft Terminal and bash shell used by Cmder.

Environment

Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.18362.0 Microsoft Windows NT 10.0.18362.0

Steps to reproduce

npm run [some script]

Where the script produces terraform errors.

Expected behavior

Normal display

Actual behavior

Non-interpreted escape codes

Originally created by @derekgreer on GitHub (Mar 1, 2021). Originally assigned to: @DHowett on GitHub. <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 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. --> # The problem: ###Microsoft Terminal with errors: ![image](https://user-images.githubusercontent.com/210185/109440111-ac073000-79f6-11eb-8bc0-8916fcd570ce.png) ### Git Bash Terminal ![image](https://user-images.githubusercontent.com/210185/109440141-c4774a80-79f6-11eb-91f7-cce25dc2b97f.png) ### Cmder Terminal ![image](https://user-images.githubusercontent.com/210185/109440225-1ae48900-79f7-11eb-93ab-e56ad0093faa.png) Same behavior with Microsoft Terminal and bash shell used by Cmder. # Environment ``` Platform ServicePack Version VersionString -------- ----------- ------- ------------- Win32NT 10.0.18362.0 Microsoft Windows NT 10.0.18362.0 ``` # Steps to reproduce ```npm run [some script] ``` Where the script produces terraform errors. <!-- A description of how to trigger this bug. --> # Expected behavior Normal display # Actual behavior Non-interpreted escape codes
claunia added the Priority-3Area-VTIssue-DocsProduct-Meta labels 2026-01-31 03:24:18 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Mar 1, 2021):

Which version of npm are you using? And where is it installed? And which version of git bash / mingw?

This looks like this isn't npm.exe, that would actually use SetConsoleMode to enable VT processing. Looks like it's just relying on that already being enabled.

@zadjii-msft commented on GitHub (Mar 1, 2021): Which version of `npm` are you using? And where is it installed? And which version of git bash / mingw? This looks like this isn't `npm.exe`, that would actually use `SetConsoleMode` to enable VT processing. Looks like it's just relying on that already being enabled.
Author
Owner

@derekgreer commented on GitHub (Mar 1, 2021):

I'm using npm v7.5.3 installed in C:\Program Files\nodejs\npm. The examples above are Windows Terminal/PowerShell, mintty/GNU bash, version 4.4.23(1)-release (x86_64-pc-msys), and Cmder/Cygwin GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin) respectively. The Windows Terminal acts the same with my Cygwin Bash though.

@derekgreer commented on GitHub (Mar 1, 2021): I'm using npm v7.5.3 installed in C:\Program Files\nodejs\npm. The examples above are Windows Terminal/PowerShell, mintty/GNU bash, version 4.4.23(1)-release (x86_64-pc-msys), and Cmder/Cygwin GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin) respectively. The Windows Terminal acts the same with my Cygwin Bash though.
Author
Owner

@TylerEich commented on GitHub (Mar 3, 2021):

I'm having a similar issue, but mine doesn't involve npm.

I use this script to fetch latest code. It depends on posh-git:

function lt {
    $rebase = Test-Path .git\rebase-merge
    if ($rebase) {
        Write-Prompt 'Continuing rebase...' -ForegroundColor ([System.ConsoleColor]::DarkGray)
        git rebase --continue
    }
    else {
        $dirty = $(git status --porcelain)
        if ($dirty) {
            Write-Prompt 'Stashing uncommitted changes...' -ForegroundColor ([System.ConsoleColor]::DarkGray)
            git stash -u
        }

        Write-Prompt 'Getting latest code...' -ForegroundColor ([System.ConsoleColor]::DarkGray)
        $branch = git rev-parse --abbrev-ref HEAD
        if ($branch -ne "master") {
            git fetch origin master:master
        }
        git pull --rebase

        if ($dirty) {
            Write-Prompt 'Reapplying uncommitted changes...' -ForegroundColor ([System.ConsoleColor]::DarkGray)
            git stash pop
        }
    }

    if ($?) {
        if (Test-Path .git\rebase-merge) {
            Write-Prompt 'Merge conflict needs to be resolved.' -ForegroundColor ([System.ConsoleColor]::Blue)
        } else {
            Write-Prompt 'Pull succeeded.' -ForegroundColor ([System.ConsoleColor]::Green)
        }
    } else {
        Write-Prompt 'Something went wrong.' -ForegroundColor ([System.ConsoleColor]::Red)
    }
}

When I run it the first time, it displays the color escape codes incorrectly (that long wonky-looking bit at the end is my prompt):
image
[Contents of git pull redacted]
image

When I run it a second time (when there's nothing to pull), it displays the colors correctly:
image

I'm using Windows Terminal 1.5.10411.0, PowerShell 7.1.2, posh-git v1.0.0-beta5, and git 2.30.1.windows.1. My font is JetBrains Mono.

@TylerEich commented on GitHub (Mar 3, 2021): I'm having a similar issue, but mine doesn't involve npm. I use this script to fetch latest code. It depends on posh-git: ```powershell function lt { $rebase = Test-Path .git\rebase-merge if ($rebase) { Write-Prompt 'Continuing rebase...' -ForegroundColor ([System.ConsoleColor]::DarkGray) git rebase --continue } else { $dirty = $(git status --porcelain) if ($dirty) { Write-Prompt 'Stashing uncommitted changes...' -ForegroundColor ([System.ConsoleColor]::DarkGray) git stash -u } Write-Prompt 'Getting latest code...' -ForegroundColor ([System.ConsoleColor]::DarkGray) $branch = git rev-parse --abbrev-ref HEAD if ($branch -ne "master") { git fetch origin master:master } git pull --rebase if ($dirty) { Write-Prompt 'Reapplying uncommitted changes...' -ForegroundColor ([System.ConsoleColor]::DarkGray) git stash pop } } if ($?) { if (Test-Path .git\rebase-merge) { Write-Prompt 'Merge conflict needs to be resolved.' -ForegroundColor ([System.ConsoleColor]::Blue) } else { Write-Prompt 'Pull succeeded.' -ForegroundColor ([System.ConsoleColor]::Green) } } else { Write-Prompt 'Something went wrong.' -ForegroundColor ([System.ConsoleColor]::Red) } } ``` When I run it the first time, it displays the color escape codes incorrectly (that long wonky-looking bit at the end is my prompt): ![image](https://user-images.githubusercontent.com/3460063/109821361-e396f780-7c03-11eb-9666-0955a98d56e2.png) `[Contents of git pull redacted]` ![image](https://user-images.githubusercontent.com/3460063/109822822-53f24880-7c05-11eb-8d3b-2f2f3f9abffd.png) When I run it a second time (when there's nothing to pull), it displays the colors correctly: ![image](https://user-images.githubusercontent.com/3460063/109822734-3c1ac480-7c05-11eb-8e99-678e3b97f3b6.png) I'm using Windows Terminal 1.5.10411.0, PowerShell 7.1.2, posh-git v1.0.0-beta5, and git 2.30.1.windows.1. My font is JetBrains Mono.
Author
Owner

@flupec commented on GitHub (Mar 25, 2021):

Suffer from this issue too on Cygwin + Windows Terminal

@flupec commented on GitHub (Mar 25, 2021): Suffer from this issue too on Cygwin + Windows Terminal
Author
Owner

@zadjii-msft commented on GitHub (Mar 26, 2021):

(I'm assigning Dustin because he's got an idea for an FAQ for the docs for this kind of issue)

@zadjii-msft commented on GitHub (Mar 26, 2021): (I'm assigning Dustin because he's got an idea for an FAQ for the docs for this kind of issue)
Author
Owner

@mikofski commented on GitHub (May 29, 2021):

I am also seeing this when using Django manage command in a Git-Bash shell ,

image

but oddly, it works fine in CMD.

image

@mikofski commented on GitHub (May 29, 2021): I am also seeing this when using Django manage command in a Git-Bash shell , ![image](https://user-images.githubusercontent.com/1385621/120054911-a0bca400-bfe7-11eb-9acb-3daa6cf6fc9b.png) but oddly, it works fine in CMD. ![image](https://user-images.githubusercontent.com/1385621/120054882-7a970400-bfe7-11eb-8baf-784e7a69f559.png)
Author
Owner

@zadjii-msft commented on GitHub (Sep 15, 2021):

Also related: #4921

@zadjii-msft commented on GitHub (Sep 15, 2021): Also related: #4921
Author
Owner

@zadjii-msft commented on GitHub (Jul 25, 2022):

Another example of cases where this is broken (and deserves a proper FAQ writeup): #13572

@zadjii-msft commented on GitHub (Jul 25, 2022): Another example of cases where this is broken (and deserves a proper FAQ writeup): #13572
Author
Owner

@3N4N commented on GitHub (Jul 26, 2022):

deserves a proper FAQ writeup

Does that mean there is a solution? I see above that Dustin was supposed to write one, but I can't find it.

Also, why does it not affect cmd? mikofski said so and I can confirm.

@3N4N commented on GitHub (Jul 26, 2022): > deserves a proper FAQ writeup Does that mean there is a solution? I see above that Dustin was supposed to write one, but I can't find it. Also, why does it not affect cmd? [mikofski said so](https://github.com/microsoft/terminal/issues/9312#issuecomment-850750558) and I can confirm.
Author
Owner

@DHowett commented on GitHub (Jul 26, 2022):

I see above that Dustin was supposed to write one, but I can't find it.

Huh. I should write this stuff down!

So, the reason it would apply in one shell and not the other is that they take different approaches to enabling/disabling the VT_PROCESSING mode for client applications.

I believe PowerShell explicitly turns VT off when it spawns a client and turns it back on before displaying the prompt, whereas CMD restores the original console mode when it spawns a client and turns it back on before displaying the prompt.

In this case, the difference between "turning VT off" and "restoring the original mode" becomes critically important: in Terminal, the original mode that CMD restores already has VT turned on, so when msys2 comes to save/restore the mode on its own, VT is already on.

@DHowett commented on GitHub (Jul 26, 2022): > I see above that Dustin was supposed to write one, but I can't find it. Huh. I should write this stuff down! So, the reason it would apply in one shell and not the other is that they take different approaches to enabling/disabling the VT_PROCESSING mode for client applications. I believe PowerShell _explicitly turns VT off_ when it spawns a client and turns it back on before displaying the prompt, whereas CMD _restores the original console mode_ when it spawns a client and turns it back on before displaying the prompt. In this case, the difference between "turning VT off" and "restoring the original mode" becomes critically important: in Terminal, the original mode that CMD restores already has VT turned on, so when msys2 comes to save/restore the mode on its own, VT is already on.
Author
Owner

@tregusti commented on GitHub (Nov 7, 2022):

Having the same issue when running Git bash in Terminal, executing Azure CLI commands.

image

Windows.Terminal: Version: 1.15.2874.0
Shell executable is C:\Program Files\Git\bin\bash.exe.

bash --version

4.4.23(1)-release

git --version

git version 2.36.0.windows.1

az --version

azure-cli                         2.37.0 *

core                              2.37.0 *
telemetry                          1.0.6 *

Dependencies:
msal                            1.18.0b1
azure-mgmt-resource             21.1.0b1

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\jes635\.azure\cliextensions'

Python (Windows) 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 22:57:10) [MSC v.1929 32 bit (Intel)]
@tregusti commented on GitHub (Nov 7, 2022): Having the same issue when running Git bash in Terminal, executing Azure CLI commands. ![image](https://user-images.githubusercontent.com/1891942/200296867-9b451672-7a92-471c-81a8-d2a85ef5203f.png) Windows.Terminal: Version: 1.15.2874.0 Shell executable is `C:\Program Files\Git\bin\bash.exe`. ### `bash --version` `4.4.23(1)-release` ### `git --version` `git version 2.36.0.windows.1` ### `az --version` ``` azure-cli 2.37.0 * core 2.37.0 * telemetry 1.0.6 * Dependencies: msal 1.18.0b1 azure-mgmt-resource 21.1.0b1 Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' Extensions directory 'C:\Users\jes635\.azure\cliextensions' Python (Windows) 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 22:57:10) [MSC v.1929 32 bit (Intel)] ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12761