colorama color doesn't reset properly when redirecting pip to stdout
Closed this issue ยท 10 comments
Environment
- pip version: Requirement already satisfied: pip in c:\python\lib\site-packages (19.0.3)
- Python version: Python 3.7.2
- OS: Windows 10 64 Bit
Using system interpreter
Description
The command line in windows stays red after entering a certain incorrect command, not all commands give this error. This happens in CMD and Powershell, I can't say about Linux or Mac.
It looks like this issue had occurred before - #2817 (Closed)
Expected behavior
It is obvious, the expected behavior is that it should reset the colors back to white, after the error is over. Looks like someone forgot to reset in colorama.
How to Reproduce
Just type 'pip install > xyz' and this bug will appear. Also it only happens with the '>' symbol, and not with any other thing.
Can you see if this happened with version 18.1?
This might be stating the obvious, but two possibilities occur to me. Either--
- the redirect operator
>
is sending the color termination characters to the file you are redirecting to, or - the use of the redirect operator is causing colorama to behave differently (e.g. causing it not to appear as a TTY).
I also wonder if this is a bug in colorama vs. pip's use of it.
>>> import colorama as c
>>> c.init()
>>> x=c.Fore.RED+"pip install > xyz"+c.Style.RESET_ALL
>>> print(x)
This code is working fine and the lines below it aren't colored in RED. So it shouldn't be a colorama related issue.
This code is working fine and the lines below it aren't colored in RED. So it shouldn't be a colorama related issue.
The example you provided doesn't tell me it's not a colorama issue. All it says to me is that one particular combination of calls may work in one setting. Have you looked at what API's pip is using to invoke colorama?
Also, colorama's tracker seems to have a number of issues around Windows, various edge cases around TTY, redirection, etc. As one example, a very quick search yielded this issue, which seems similar to what you're reporting here (with title "Windows: Style.RESET_ALL does not work if stdout is redirected"): tartley/colorama#200
I tried to reproduce this issue tartley/colorama#200 , but it now no longer happening.
Also, even if the issue occurs due to colorama, can't we apply a fix until the issue is fixed in colorama module.
Also, as you have said to look for the API's which pip uses to invoke colorama, I don't know how to look for that (not very experienced with open-source projects).
I tried to reproduce this issue tartley/colorama#200 , but it now no longer happening.
FYI, you didn't follow their instructions. You need to put those lines in a separate file and then execute from the command-line (not Python prompt).
Also, even if the issue occurs due to colorama, can't we apply a fix until the issue is fixed in colorama module.
The policy here would be to fix the issue in colorama. It seems like it would be doable to me, if I were to guess.
I filed an issue for this in colorama's tracker here: tartley/colorama#218
Great, hope they fix it soon.