Browse Source
Add Pycharm support to coloured logging
pull/9059/head
Tom
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
5 additions and
2 deletions
-
discord/utils.py
|
|
@ -1208,14 +1208,17 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None) |
|
|
|
|
|
|
|
|
|
|
|
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): |
|
|
|