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
Add Win 10 native ANSI cmd support #105
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,20 @@ def is_a_tty(stream): | |
return hasattr(stream, 'isatty') and stream.isatty() | ||
|
||
|
||
def check_win_10_ansi_support(): | ||
import winreg | ||
|
||
# Check the registry for release ID | ||
key = r"SOFTWARE\Microsoft\Windows NT\CurrentVersion" | ||
val = r"ReleaseID" | ||
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key) | ||
releaseId = int(winreg.QueryValueEx(key,val)[0]) | ||
winreg.CloseKey(key) | ||
|
||
# Windows 10 supports ANSI cmd since release 1511 | ||
return releaseId >= 1511 | ||
|
||
|
||
class StreamWrapper(object): | ||
''' | ||
Wraps a stream (such as stdout), acting as a transparent proxy for all | ||
|
@@ -66,13 +80,16 @@ def __init__(self, wrapped, convert=None, strip=None, autoreset=False): | |
# to support the ANSI codes. | ||
conversion_supported = on_windows and winapi_test() | ||
|
||
# Does this version of Win 10 support ANSI? | ||
win_10_ansi_support = on_windows and check_win_10_ansi_support() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change the name to "windows_ansi_support", in case it will be more than just Windows 10 in the future :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, also changed the function name. |
||
|
||
# should we strip ANSI sequences from our output? | ||
if strip is None: | ||
if strip is None and not win_10_ansi_support: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to add the win10 check inside the if, this way "strip" will always be True/False and not be left as None. Same for 'convert' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
strip = conversion_supported or (not is_stream_closed(wrapped) and not is_a_tty(wrapped)) | ||
self.strip = strip | ||
|
||
# should we should convert ANSI sequences into win32 calls? | ||
if convert is None: | ||
if convert is None and not win_10_ansi_support: | ||
convert = conversion_supported and not is_stream_closed(wrapped) and is_a_tty(wrapped) | ||
self.convert = convert | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to replace the windows release check using the "platform" module? platform.win32_ver() or platform.platform()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found a way to check the build version using the platform module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Slayther Try
sys.getwindowsversion()[2]
.