Skip to content
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] Coloring does not work in PyCharm #206

Closed
akrk1986 opened this issue Aug 4, 2020 · 22 comments
Closed

[BUG] Coloring does not work in PyCharm #206

akrk1986 opened this issue Aug 4, 2020 · 22 comments
Labels
upstream Bug is in a dependancy

Comments

@akrk1986
Copy link

akrk1986 commented Aug 4, 2020

Just checked - it seems to be a PyCharm problem, I will report it there, so this report is just FYI for rich users who use PyCharm.
It works in the PyCharm terminal (command line), but not inside the stdout pane of PyCharm.

Reproduction
Replace print() statement with console.print(string, style='bold red'). The string is printed, but no coloring.

from rich.console import Console
console = Console()
console.print('==> Mismatches were found in one or more platforms <==', style='bold red')

Windows 10, PyCharm Community (lastest), Python 3.8, Rich 5.0.0

@willmcgugan willmcgugan added upstream Bug is in a dependancy and removed Needs triage labels Aug 4, 2020
@willmcgugan
Copy link
Collaborator

It could be a problem with auto-detection.

What does the following print in PyCharm?

print(console.color_system)

@akrk1986
Copy link
Author

akrk1986 commented Aug 4, 2020

In the PyCharm stdout window, as you've suspected, it prints 'None' (and no color).
In the PyCharm terminal, it prints 'windows' (and works)

@willmcgugan
Copy link
Collaborator

Interesting. That suggest the stdout window is not an embedded console. Rich will disable color if it detects it is not connected to a real terminal.

You could try this:

console = Console(color_system="windows")

That will force Rich to write color, but if PyCharm can't handle it, you may end up with garbage.

@akrk1986
Copy link
Author

akrk1986 commented Aug 4, 2020

Thanks - it works. Since I only use Windows for this project, this workaround is good enough. Should I submit a bug to PyCharm?

@willmcgugan
Copy link
Collaborator

Might be worth filing a bug report. Tell them that isatty() is returning False.

@willmcgugan
Copy link
Collaborator

@akrk1986 going to close this one, but let me know if you get a response from PyCharm devs...

@akrk1986
Copy link
Author

akrk1986 commented Aug 4, 2020

Will let you know. Thanks a lot for the quick response and great package!

@akrk1986
Copy link
Author

akrk1986 commented Aug 9, 2020

Just FYI, bug was accepted by PyCharm: Issue PY-43860

@akrk1986
Copy link
Author

Hi Will,
Here is the answer I got from PyCharm:
"Hi, have you tried to enable emulate terminal in output console option in run/debug configuration? This should do the trick."
It seems that the non-terminal behavior is the default in PyCharm.
IMHO, it's worth mentioning in the rich documentation, perhaps under 'known issues'.
Unfortunately, I don't have time to submit a PR for that.
Keep up the good work!
Amir

@ChristianSauer
Copy link

@akrk1986 Thank you. I have used for the first time and was wondering why no progress bar was visible at all - setting the emulation fixes this. WOuld be great if this is in the docs.

@j4hangir
Copy link

Hi Will,
Here is the answer I got from PyCharm:
"Hi, have you tried to enable emulate terminal in output console option in run/debug configuration? This should do the trick."
It seems that the non-terminal behavior is the default in PyCharm.
IMHO, it's worth mentioning in the rich documentation, perhaps under 'known issues'.
Unfortunately, I don't have time to submit a PR for that.
Keep up the good work!
Amir

You're right, please add this to the docs.

@willmcgugan
Copy link
Collaborator

It's on the first page in a blue box. https://rich.readthedocs.io/en/latest/introduction.html

@j4hangir
Copy link

It's on the first page in a blue box. https://rich.readthedocs.io/en/latest/introduction.html

Thanks 👍🏻 I meant in github but I guess that'll do as well.

Out of curiosity, is there no easy way to make it work out of the box? The other libs I used before usually worked in PyCharm without the need for emulate in terminal.

@willmcgugan
Copy link
Collaborator

Not without breaking things for other users.

@cowwoc
Copy link

cowwoc commented Nov 9, 2021

FYI, per https://youtrack.jetbrains.com/issue/PY-29204 it looks IntelliJ removed this feature. There is no such option in version 2021.2.3 and no indication of when it will come back. Are there any other workarounds?

I filed a new bug report at https://youtrack.jetbrains.com/issue/PY-51507

@kageanrage
Copy link

I'm also unable to make this work in PyCharm in Windows, and unsure how to apply Will's suggestion:

console = Console(color_system="windows")

@togrul2
Copy link

togrul2 commented Jul 5, 2022

Hi, In PyCharm 2022.1.3 seems there is no emulate terminal in output console for run configurations. Still have that problem with red logs in the console. Does anyone know how to solve this problem?

@tjnd89
Copy link

tjnd89 commented Feb 3, 2023

@AntonyMilneQB see https://stackoverflow.com/questions/20333674/pycharm-logging-output-colours. I think if you change your streamhandler to explicitly write to stdout it should get rid of the red logs.

@Biblebrox
Copy link

изображение
изображение

@nonchris
Copy link

nonchris commented Sep 3, 2024

This solved the problem for me too.
Note: Pycharm moved that option to "Modify option" in the Run Config menu with their UI rework.
image

@Liquidmasl
Copy link

Emulate terminal works so that we have colors, but it doesnt work as debug console anymore, which is quite annoying ):

@tjnd89
Copy link

tjnd89 commented Sep 18, 2024

Emulate terminal works so that we have colors, but it doesnt work as debug console anymore, which is quite annoying ):

@Liquidmasl unfortunately this is something PyCharm has to fix, not a Textualize issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Bug is in a dependancy
Projects
None yet
Development

No branches or pull requests