Skip to content
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

Native VT support in Windows #197

Open
peterbrittain opened this issue Jan 11, 2019 · 4 comments
Open

Native VT support in Windows #197

peterbrittain opened this issue Jan 11, 2019 · 4 comments

Comments

@peterbrittain
Copy link
Owner

According to a dev blog (https://blogs.msdn.microsoft.com/commandline/2018/12/10/new-experimental-console-features/), Windows 10 natively supports ANSI escape codes sufficiently well to run most Linux curses apps inside WSL. That should mean that we can get a much better experience for Windows 10 users if we create a new Screen sub-class that simply uses the ANSI escape codes instead of the win32 console API.

A quick trial shows that ANSI escape codes inside CMD.exe do indeed work and provide at least 256 colour support. Nice!

The idea here is that we give Windows 10 users a much better experience by spotting this at the time the Screen is opened and giving an ANSI terminal instead. In theory this is almost exactly the existing _CursesScreen implementation (for colours and cursor movement), but with hard-coded ANSI escape codes.

@Eeems
Copy link

Eeems commented Jan 11, 2019

Be aware that before Windows 10 build 1809 you could crash the console with certain ANSI codes.
Eeems/intercessions#1
tartley/colorama#139
microsoft/terminal#162

@peterbrittain
Copy link
Owner Author

Well worth knowing before I invest too much time into this. Thanks.

In case you're interested, I've found that all the sample code is running fine in WSL (using a Linux Python installation). It's nice to (finally) see the animated Julia set running full colour in Windows!

@Eeems
Copy link

Eeems commented Aug 29, 2019

@peterbrittain a fix has been delivered in 1809, you can probably start looking into this now :)

@iamthad
Copy link

iamthad commented Jul 25, 2020

In case it helps, this is a minimal working example of enabling the support:

import platform
if platform.system() == 'Windows':
    from ctypes import windll
    kernel32 = windll.kernel32
    try:
        kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), kernel32.GetConsoleMode()|7)
    except Exception as e:
        raise OSError("Could not enable color handling") from e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@Eeems @iamthad @peterbrittain and others