Skip to content

Color Escape Codes displayed incorrectly #9312

Open

Description

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

Activity

  1. ghost added
    Needs-Triage
    on Mar 1, 2021
  2. ghost added
    Needs-Tag-Fix
    on Mar 1, 2021
  3. changed the title [-]Code Escape Codes displayed incorrectly[/-] [+]Color Escape Codes displayed incorrectly[/+] on Mar 1, 2021
  4. zadjii-msft commented on Mar 1, 2021

    @zadjii-msft
    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.

  5. added
    Needs-Author-Feedback
    on Mar 1, 2021
  6. derekgreer commented on Mar 1, 2021

    @derekgreer
    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.

  7. ghost added
    Needs-Attention
    on Mar 1, 2021
  8. ghost removed
    Needs-Author-Feedback
    on Mar 1, 2021
  9. TylerEich commented on Mar 3, 2021

    @TylerEich

    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.

  10. flupec commented on Mar 25, 2021

    @flupec

    Suffer from this issue too on Cygwin + Windows Terminal

  11. zadjii-msft commented on Mar 26, 2021

    @zadjii-msft
    Member

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

  12. added
    Area-VT
    Issue-Docs
    Product-Meta
    and removed
    Needs-Attention
    Needs-Triage
    on Mar 26, 2021
  13. ghost removed
    Needs-Tag-Fix
    on Mar 26, 2021
  14. mikofski commented on May 29, 2021

    @mikofski

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

    image

    but oddly, it works fine in CMD.

    image

  15. zadjii-msft commented on Sep 15, 2021

    @zadjii-msft
    Member

    Also related: #4921

  16. zadjii-msft commented on Jul 25, 2022

    @zadjii-msft
    Member

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

  17. 3N4N commented on Jul 26, 2022

    @3N4N

    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.

  18. DHowett commented on Jul 26, 2022

    @DHowett
    Member

    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.

  19. tregusti commented on Nov 7, 2022

    @tregusti

    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

Metadata

Metadata

Labels

Area-VTIssue-DocsPriority-3Product-Meta

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions