From bb931272fc0724039cc435cf0f9dd32bf5b3409c Mon Sep 17 00:00:00 2001 From: Tom <47765953+IAmTomahawkx@users.noreply.github.com> Date: Thu, 27 Oct 2022 07:06:29 -0700 Subject: [PATCH] Add Pycharm support to coloured logging --- discord/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 18691e7d4..1282ef5f9 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1455,14 +1455,17 @@ def _get_browser_version(user_agent: str) -> str: def stream_supports_colour(stream: Any) -> bool: + # Pycharm and Vscode support colour in their inbuilt editors + if 'PYCHARM_HOSTED' in os.environ or os.environ.get('TERM_PROGRAM') == 'vscode': + return True + is_a_tty = hasattr(stream, 'isatty') and stream.isatty() if sys.platform != 'win32': return is_a_tty # ANSICON checks for things like ConEmu # WT_SESSION checks if this is Windows Terminal - # VSCode built-in terminal supports colour too - return is_a_tty and ('ANSICON' in os.environ or 'WT_SESSION' in os.environ or os.environ.get('TERM_PROGRAM') == 'vscode') + return is_a_tty and ('ANSICON' in os.environ or 'WT_SESSION' in os.environ) class _ColourFormatter(logging.Formatter):