diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-05-20 03:02:25 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2022-05-20 06:01:09 +0530 |
commit | 53973b4d2cb349d39d6f240911142b330d1dd80d (patch) | |
tree | 91527a9e54f0bfa0339da481222402506921e1c1 /yt_dlp/utils.py | |
parent | b801cd7179c9546f4054dc534ec4b713e09976a7 (diff) | |
download | hypervideo-pre-53973b4d2cb349d39d6f240911142b330d1dd80d.tar.lz hypervideo-pre-53973b4d2cb349d39d6f240911142b330d1dd80d.tar.xz hypervideo-pre-53973b4d2cb349d39d6f240911142b330d1dd80d.zip |
[utils] Fix bug in 0b9c08b47bb5e95c21b067044ace4e824d19a9c2
* Cache of `supports_terminal_sequences` must be reset after enabling VT mode
* and move `windows_enable_vt_mode` to utils to avoid cyclic imports
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r-- | yt_dlp/utils.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 0274e330d..78789b1c5 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -5094,10 +5094,12 @@ def jwt_decode_hs256(jwt): return payload_data +WINDOWS_VT_MODE = False if compat_os_name == 'nt' else None + + @functools.cache def supports_terminal_sequences(stream): if compat_os_name == 'nt': - from .compat import WINDOWS_VT_MODE # Must be imported locally if not WINDOWS_VT_MODE or get_windows_version() < (10, 0, 10586): return False elif not os.getenv('TERM'): @@ -5108,6 +5110,21 @@ def supports_terminal_sequences(stream): return False +def windows_enable_vt_mode(): # TODO: Do this the proper way https://bugs.python.org/issue30075 + if compat_os_name != 'nt': + return + global WINDOWS_VT_MODE + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + try: + subprocess.Popen('', shell=True, startupinfo=startupinfo).wait() + except Exception: + return + + WINDOWS_VT_MODE = True + supports_terminal_sequences.cache_clear() + + _terminal_sequences_re = re.compile('\033\\[[^m]+m') |