-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-enable ANSI console color for Windows 10.16257 and later #15758
Comments
Do you perhaps know if such a setting also exists for PowerShell? |
I don't, but it's possible it might just work now. As I noted, the 3 instances of Glenn |
...since I have those changes here locally I just gave it a try and yes, it does work for PowerShell too. (And hmm, why am I never using PowerShell in general?...) |
On further consideration, and even better idea would be to have youtube-dl explicitly enable/disable ANSI color on Windows using the Win32 API SetConsoleMode. This would restore the ability for the user to control of the feature on Windows—via the existing I implemented this change in a updated version of the youtube-dl function _windows_write_string from the file .../youtube-dl/utils.py. The following is a complete replacement for that function. Beyond cleanup/modernization overhaul, the substantive change in this code is that ANSI VT mode will be enabled, if necessary, for the stdout and stderr handles (the state persists for each, so the calls to
If someone wants to merge in this code, the following lines should also be changed to remove the Many thanks if someone is willing to help pull this code, since I am not yet fully adept at GitHub. |
ping. Does anybody want to help push the changes I included above? It has been working super-great for me locally. |
In Windows 10 build 16257 (released last year) and later, ANSI color and escape sequences for the built-in
cmd.exe
console ("conhost") are subject to the following registry key:See MSDN blogs for more information. There's also some official MSDN docs and a bunch of articles on StackOverflow, such as here and here. There's also some critical information on this subject in this github comment.
This new capability means that the following lines of code in youtube-dl are overly-restrictive:
https://github.com/rg3/youtube-dl/blob/f9f10268c1816dcf1fc0db9d8128008f73a154c7/youtube_dl/extractor/common.py#L782
https://github.com/rg3/youtube-dl/blob/f9f10268c1816dcf1fc0db9d8128008f73a154c7/youtube_dl/YoutubeDL.py#L596
https://github.com/rg3/youtube-dl/blob/f9f10268c1816dcf1fc0db9d8128008f73a154c7/youtube_dl/YoutubeDL.py#L608
On Windows 10, the value of
compat_os_name
is "nt". Because the lines listed above subsume all three cases where youtube-dl references the--no-color
command-line option, the end result is that the--no-color
option always asserted on Windows (that is, regardless of not specifying--no-color
).Relaxing the three conjunctions shown above, by removing the
and compat_os_name != 'nt'
term from each, allows for ANSI color on Windows 10 (assuming the system-wide default is 'enabled' as specified by the registry key mentioned above).The text was updated successfully, but these errors were encountered: