diff --git a/colorama/ansitowin32.py b/colorama/ansitowin32.py index 8177d5b..5d91761 100644 --- a/colorama/ansitowin32.py +++ b/colorama/ansitowin32.py @@ -21,6 +21,23 @@ def is_a_tty(stream): return hasattr(stream, 'isatty') and stream.isatty() +def check_windows_ansi_support(): + try: + import winreg + except ImportError: + return False + + # 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 @@ -69,14 +86,17 @@ 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? + windows_ansi_support = on_windows and check_windows_ansi_support() + # should we strip ANSI sequences from our output? if strip is None: - strip = conversion_supported or (not is_stream_closed(wrapped) and not is_a_tty(wrapped)) + strip = conversion_supported or not windows_ansi_support 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: - convert = conversion_supported and not is_stream_closed(wrapped) and is_a_tty(wrapped) + convert = not windows_ansi_support or (conversion_supported and not is_stream_closed(wrapped) and is_a_tty(wrapped)) self.convert = convert # dict of ansi codes to win32 functions and parameters