mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 16:00:29 +00:00
Enable colour logging for docker even if tty is not set
This commit is contained in:
parent
7863418ddb
commit
1700086f1a
@ -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…
x
Reference in New Issue
Block a user