Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
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.execonsole ("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_nameis "nt". Because the lines listed above subsume all three cases where youtube-dl references the--no-colorcommand-line option, the end result is that the--no-coloroption 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).