Skip to content

Commit

Permalink
[core] Support NO_COLOR environment variable (#8385)
Browse files Browse the repository at this point in the history
Authored by: prettykool, Grub4K
  • Loading branch information
prettykool committed Nov 20, 2023
1 parent cc07f5c commit a0b19d3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions yt_dlp/YoutubeDL.py
Expand Up @@ -625,13 +625,16 @@ def __init__(self, params=None, auto_init=True):
'Overwriting params from "color" with "no_color"')
self.params['color'] = 'no_color'

term_allow_color = os.environ.get('TERM', '').lower() != 'dumb'
term_allow_color = os.getenv('TERM', '').lower() != 'dumb'
no_color = bool(os.getenv('NO_COLOR'))

def process_color_policy(stream):
stream_name = {sys.stdout: 'stdout', sys.stderr: 'stderr'}[stream]
policy = traverse_obj(self.params, ('color', (stream_name, None), {str}), get_all=False)
if policy in ('auto', None):
return term_allow_color and supports_terminal_sequences(stream)
if term_allow_color and supports_terminal_sequences(stream):
return 'no_color' if no_color else True
return False
assert policy in ('always', 'never', 'no_color'), policy
return {'always': True, 'never': False}.get(policy, policy)

Expand Down

0 comments on commit a0b19d3

Please sign in to comment.