-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[BUG] Color is not outputted on Git Bash #988
Comments
Relevant issue: tartley/colorama#224 It seems there is a PR on Colorama that would fix the issue, but it has not been merged yet: tartley/colorama#226 |
Thanks for doing the research there. Detecting terminal capabilities on Windows is messy. I think that detecting the TERM env var may be enough to disable the legacy_windows check. I'll give it some thought. I'd also accept a PR if you want to tackle it. |
I can give it a try. Do you think it makes sense to handle the |
Additional context: I'm trying to create a Git pre-commit hook to run a Python script that uses Rich for colored output. When running the pre-commit hook on Linux, everything works fine. When running on Windows, I don't get any colors on any Terminal (Windows Terminal, regular |
I think the reason you don't get colors in some environments, is that Colorama strips all ANSI codes if it thinks that it is not writing to a terminal.
That might work. The problem is that it has global effect. An app could have several Console instances with different settings, writing in different threads. The ideal solution would be to isolate the Colorama magic to a single Console instance. I briefly tackled that, but didn't manage to make it work. So I'm not sure what the best solution is. If you were to make any changes, it would have to not break Windows terminal and cmd.exe. Good luck! |
I don’t think there is a great solution to this that doesn’t require reimplementing colorama. Closing for now, but I suspect I will revisit it in future. |
Describe the bug
When running a Python script using Rich with Git Bash on Windows, color is not outputted.
To Reproduce
Simply run the following code on a Git Bash terminal:
Forcing terminal and/or disabling legacy Windows mode do not work either:
Platform
Windows 10, Git Bash (MINGW64)
Diagnose
Additional info
I've investigated the Rich coding and the problematic code seem to be related to the
colorama.init()
call.If I comment out the call to
colorama.init()
and setforce_terminal
toTrue
, then I get color on the output. Git Bash emulates BASH on Windows, so I assume it is expecting ANSI codes. However,detect_legacy_windows()
is incorrectly returningTrue
; therefore,colorama.init()
is called and ANSI codes are not outputted.I think the fix would be to make
detect_legacy_windows()
returnFalse
when running on Git Bash/MINGW, but I'm not sure how to do it.The text was updated successfully, but these errors were encountered: