Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color Escape Codes displayed incorrectly #9312

Open
derekgreer opened this issue Mar 1, 2021 · 11 comments
Open

Color Escape Codes displayed incorrectly #9312

derekgreer opened this issue Mar 1, 2021 · 11 comments
Assignees
Labels
Area-VT Virtual Terminal sequence support Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs Priority-3 A description (P3) Product-Meta The product is the management of the products.
Milestone

Comments

@derekgreer
Copy link

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

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Mar 1, 2021
@derekgreer derekgreer changed the title Code Escape Codes displayed incorrectly Color Escape Codes displayed incorrectly Mar 1, 2021
@zadjii-msft
Copy link
Member

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 zadjii-msft added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Mar 1, 2021
@derekgreer
Copy link
Author

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.

@ghost ghost added Needs-Attention The core contributors need to come back around and look at this ASAP. and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Mar 1, 2021
@TylerEich
Copy link

TylerEich commented 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.

@flupec
Copy link

flupec commented Mar 25, 2021

Suffer from this issue too on Cygwin + Windows Terminal

@zadjii-msft
Copy link
Member

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

@zadjii-msft zadjii-msft added Area-VT Virtual Terminal sequence support Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs Product-Meta The product is the management of the products. and removed Needs-Attention The core contributors need to come back around and look at this ASAP. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Mar 26, 2021
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Mar 26, 2021
@zadjii-msft zadjii-msft added this to the Terminal v2.0 milestone Mar 26, 2021
@mikofski
Copy link

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

image

but oddly, it works fine in CMD.

image

@zadjii-msft
Copy link
Member

Also related: #4921

@zadjii-msft zadjii-msft added the Priority-3 A description (P3) label Jan 4, 2022
@zadjii-msft zadjii-msft modified the milestones: Terminal v2.0, 22H2 Jan 4, 2022
@zadjii-msft
Copy link
Member

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

@3N4N
Copy link

3N4N commented 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.

@DHowett
Copy link
Member

DHowett commented 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.

@tregusti
Copy link

tregusti commented 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)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support Issue-Docs It's a documentation issue that really should be on MicrosoftDocs/Console-Docs Priority-3 A description (P3) Product-Meta The product is the management of the products.
Projects
None yet
Development

No branches or pull requests

8 participants