Browse Source

Enable colour logging for docker even if tty is not set

pull/9165/head
Rapptz 2 years ago
parent
commit
1700086f1a
  1. 8
      discord/utils.py

8
discord/utils.py

@ -1207,6 +1207,11 @@ def format_dt(dt: datetime.datetime, /, style: Optional[TimestampStyle] = None)
return f'<t:{int(dt.timestamp())}:{style}>'
def is_docker() -> bool:
path = '/proc/self/cgroup'
return os.path.exists('/.dockerenv') or (os.path.isfile(path) and any('docker' in line for line in open(path)))
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':
@ -1214,7 +1219,8 @@ def stream_supports_colour(stream: Any) -> bool:
is_a_tty = hasattr(stream, 'isatty') and stream.isatty()
if sys.platform != 'win32':
return is_a_tty
# Docker does not consistently have a tty attached to it
return is_a_tty or is_docker()
# ANSICON checks for things like ConEmu
# WT_SESSION checks if this is Windows Terminal

Loading…
Cancel
Save