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
No longer works for output in Jupyter #28
Comments
Please can you give more info? A minimal reproducible example would help: https://stackoverflow.com/help/minimal-reproducible-example What did you do? What did you expect? What actually happened? |
Thank you! Please can you let me know the value of each of the conditions in print("ANSI_COLORS_DISABLED" in os.environ)
print("NO_COLOR" in os.environ)
print("FORCE_COLOR" in os.environ)
print(hasattr(sys.stdout, "isatty"))
print(hasattr(sys.stdout, "isatty") and sys.stdout.isatty())
print(os.environ.get("TERM") != "dumb") |
Possibly of value, |
Thanks, so the problem is Jupyter is returning Looks like they were going to set it to return I'll dig a bit more, the short term workaround is to set an env var |
I asked over at ipython/ipykernel#1024. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@mcrutch Please can you retest with IPython Kernel for Jupyter v6.18.0? This should now be fixed. |
A simple example how to reproduce this problem with the
|
@realtimeprojects This issue is for Jupyter. If you're piping the output then we have no idea if the receiving program can accept the colour codes, that's why we're doing tty detection. If you want to force it, please use the env var: FORCE_COLOR=1 python3 -m termcolor | tee test.log |
I was just commenting on this issue because I think this is a generic problem and not specific to Jupyter. Sorry for that! I think it is a bad idea to check the sys.stdout for "isatty()" since you don't know where your colorized message will go to. It is not guaruanteed that it will be streamed to sys.stdout (or sys.stderr). This is very application specific. And even if the output stream is not a tty it might still support colorization, what I assume is the case for Jupyter or any integrated environment simulating a terminal. I use termcolor for colorizing "python logging" messages, which go to sys.stderr and if I run my app and redirect stdout to a file, the logging messages are not colorized as well. This check also fails when used in azure devops pipelines. Furthermore, I consider the "isatty" check as rather "expensive" when done for each single message and you have a lot of log messages to colorize. |
Closing this issue as fixed in Jupyter: #28 (comment) @realtimeprojects Thank you for the feedback. Can you use the I'm considering adding a
Yes, I guess this is like GitHub Actions: actions/runner#241 I recommend adding |
Please see PR #38 to add parameters to override the environment variables. |
Pretty sure the _can_do_color function is the culprit. While it might not have been intentional that it worked in Jupyter, it did.
termcolor/src/termcolor/termcolor.py
Line 106 in ec269e6
The text was updated successfully, but these errors were encountered: