Color Escape codes not working in MSYS (Git Bash) #4821

Closed
opened 2026-01-30 23:57:25 +00:00 by claunia · 6 comments
Owner

Originally created by @benjamw on GitHub (Nov 5, 2019).

Environment

Windows build number: 
- Microsoft Windows [Version 10.0.18362.418]

Windows Terminal version (if applicable): 
- Windows Terminal (Preview)
- Version: 0.6.2951.0

Any other software?
- Git Bash for Windows (MINGW64)
- Ubuntu (WSL)

Steps to reproduce

Open a Git Bash tab in Windows Terminal.
Run the following script:

#!/bin/bash

# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.

for fgbg in 38 48 ; do # Foreground / Background
    for color in {0..255} ; do # Colors
        # Display the color
        printf "\e[${fgbg};5;%sm  %3s  \e[0m" $color $color
        # Display 6 colors per lines
        if [ $((($color + 1) % 6)) == 4 ] ; then
            echo # New line
        fi
    done
    echo # New line
done

exit 0

Expected behavior

Pretty colors.

Actual behavior

Only a small number of colors.

An image is attached that shows Git Bash running that script, then Git Bash in Windows Terminal running that script, and finally Ubuntu in Windows Terminal running that script.

Git Bash shows the colors as expected, as does Ubuntu in Windows Terminal, so it seems reasonable that both Git Bash, and Windows Terminal support those colors, but somewhere between them, the colors get mangled and do not show properly.

Image3

Originally created by @benjamw on GitHub (Nov 5, 2019). # Environment ```none Windows build number: - Microsoft Windows [Version 10.0.18362.418] Windows Terminal version (if applicable): - Windows Terminal (Preview) - Version: 0.6.2951.0 Any other software? - Git Bash for Windows (MINGW64) - Ubuntu (WSL) ``` # Steps to reproduce Open a Git Bash tab in Windows Terminal. Run the following script: ```bash #!/bin/bash # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. for fgbg in 38 48 ; do # Foreground / Background for color in {0..255} ; do # Colors # Display the color printf "\e[${fgbg};5;%sm %3s \e[0m" $color $color # Display 6 colors per lines if [ $((($color + 1) % 6)) == 4 ] ; then echo # New line fi done echo # New line done exit 0 ``` # Expected behavior Pretty colors. # Actual behavior Only a small number of colors. An image is attached that shows Git Bash running that script, then Git Bash in Windows Terminal running that script, and finally Ubuntu in Windows Terminal running that script. Git Bash shows the colors as expected, as does Ubuntu in Windows Terminal, so it seems reasonable that both Git Bash, and Windows Terminal support those colors, but somewhere between them, the colors get mangled and do not show properly. ![Image3](https://user-images.githubusercontent.com/186505/68230447-48155880-ffb6-11e9-8a14-25e6f62d5b2f.png)
Author
Owner

@Biswa96 commented on GitHub (Nov 5, 2019):

What command did you run to open msys2 bash in Windows Terminal?

@Biswa96 commented on GitHub (Nov 5, 2019): What command did you run to open msys2 bash in Windows Terminal?
Author
Owner

@zadjii-msft commented on GitHub (Nov 5, 2019):

It's very suspicious that 7 had the color reversed, 30-37 had the foreground colors set to what you'd expect from ^[[31m-^[[37m, and the same with the backgrounds for 41-47.

What's TERM set to in the git bash shell running in Windows Terminal?

@zadjii-msft commented on GitHub (Nov 5, 2019): It's very suspicious that `7` had the color reversed, 30-37 had the foreground colors set to what you'd expect from `^[[31m`-`^[[37m`, and the same with the backgrounds for 41-47. What's `TERM` set to in the git bash shell running in Windows Terminal?
Author
Owner

@DHowett-MSFT commented on GitHub (Nov 5, 2019):

I'm rather certain this is the same root cause as #2837, which makes it firmly an external bug. Msys2's runtime is derived from Cygwin's.

I've debugged through conhost, and it looks like they're never sending us even a single escape sequence -- they're iterating through and calling SetConsoleTextAttribute, WriteConsole, SetConsole... where they try to change the attribute every time.

More info here: https://github.com/microsoft/terminal/issues/2837#issuecomment-533830745

@DHowett-MSFT commented on GitHub (Nov 5, 2019): I'm rather certain this is the same root cause as #2837, which makes it firmly an external bug. Msys2's runtime is derived from Cygwin's. I've debugged through conhost, and it looks like they're never sending us even a single escape sequence -- they're iterating through and calling `SetConsoleTextAttribute`, `WriteConsole`, `SetConsole...` where they try to change the attribute every time. More info here: https://github.com/microsoft/terminal/issues/2837#issuecomment-533830745
Author
Owner

@DHowett-MSFT commented on GitHub (Nov 5, 2019):

Incidentally, it looks like Cygwin upstream added support for passing through color sequences to the console host 7 month ago. Judging by the version Git for Windows ingested, they're a year out-of-date. The copyright indicates "20xx-2018".

@DHowett-MSFT commented on GitHub (Nov 5, 2019): Incidentally, it looks like Cygwin upstream added support for passing through color sequences to the console host 7 month ago. Judging by the version Git for Windows ingested, they're a year out-of-date. The copyright indicates "20xx-2018".
Author
Owner

@benjamw commented on GitHub (Nov 5, 2019):

Thanks for the info. Sorry for the duplicate issue.

@benjamw commented on GitHub (Nov 5, 2019): Thanks for the info. Sorry for the duplicate issue.
Author
Owner

@DHowett-MSFT commented on GitHub (Nov 6, 2019):

@benjamw no problem! It's hard to find these things out, and the one in question was already closed. Sorry about the lack of discoverability 😄

@DHowett-MSFT commented on GitHub (Nov 6, 2019): @benjamw no problem! It's hard to find these things out, and the one in question was already closed. Sorry about the lack of discoverability :smile:
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#4821