Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm - colored output in django console

Tags:

django

pycharm

The problem is that when I'm lauching dev-server through Kubuntu's Konsole app, debug output is colored: Konsole.png

But wher I'm launching it trough built-in "Run" or "Debug" in PyCharm, the output in PyCharm's console is all red: PyCharm.png

Is there a way to make output in PyCharm colored? Because I can't find anything related in Settings.

UPD: link to issue on PyCharm issue tracker

As I see some people woting on this question, so here is the link to this issue on PyCharm issue tracker - youtrack.jetbrains.com/issue/PY-19790. If you will vote for this feature, it will be released faster!

like image 337
Compadre Avatar asked Jun 10 '16 09:06

Compadre


People also ask

How do I make PyCharm colorful?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Color Scheme. Use the Scheme list to select a color scheme.

How do I change text color in Terminal PyCharm?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Color Scheme, and select the setting pages related to consoles: Console Colors. Console Font.

How do I change my appearance in PyCharm?

Change the UI themeIn the Settings/Preferences dialog ( Ctrl+Alt+S ), select Appearance & Behavior | Appearance. Select the UI theme from the Theme list: IntelliJ Light: Traditional light theme for IntelliJ-based IDEs. macOS Light or Windows 10 Light: OS-specific light theme available as a bundled plugin.


2 Answers

Some time ago I wrote a code snippet that does the thing for me. It's not a perfect solution, but does the trick. BSD License

To use it:

  • Option 1: git clone/download this and import it somewhere (e.g. django development settings). Read the module docstring and the readme for details.

  • Option 2: include the code snippet below into your django development/debug settings (or anywhere else, where it will be run early). It's automatically verified with SHA-2 against file changes.

try:  # Colored logger CaaS. Auto downloaded and verified.
    import os
    import hashlib
    from urllib import request
    url, sha256 = "https://lab.it.hs-hannover.de/lukyanch/pydevutils/raw/c531eaf7/colored_logger.py", "083e1a39cfdbe17a7126188b5477fb8f324be8106a39ed4a00faeb3f18c5aedc"
    cached_file = "/tmp/{0}.py".format(sha256)
    code = bool(os.path.exists(cached_file) or [request.urlretrieve(url, cached_file), print("Downloaded: " + url)]) and open(cached_file, "r").read()
    assert hashlib.sha256(code.encode()).hexdigest() == sha256, os.remove(cached_file) or "Bad content: " + cached_file
    exec(code)
except Exception as e:
    print("No colored logger: {e.__class__.__name__}: {e}".format(e=e))

enter image description here

like image 57
Art Avatar answered Oct 07 '22 07:10

Art


"grep console" is the plugin which handles this perfectly: https://plugins.jetbrains.com/plugin/7125-grep-console

like image 34
Davy Avatar answered Oct 07 '22 07:10

Davy