Mercurial > hg-stable
changeset 10989:9fb09fc3ea3c
color: handle non-standard stdout on win32
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 23 Apr 2010 14:29:44 +0200 |
parents | f2340d699e79 |
children | 11569b997f81 |
files | hgext/color.py |
diffstat | 1 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/color.py Sun Apr 25 23:36:56 2010 +0200 +++ b/hgext/color.py Fri Apr 23 14:29:44 2010 +0200 @@ -217,7 +217,7 @@ _("when to colorize (always, auto, or never)"))) try: - import re + import re, pywintypes from win32console import * # http://msdn.microsoft.com/en-us/library/ms682088%28VS.85%29.aspx @@ -243,7 +243,13 @@ } stdout = GetStdHandle(STD_OUTPUT_HANDLE) - origattr = stdout.GetConsoleScreenBufferInfo()['Attributes'] + try: + origattr = stdout.GetConsoleScreenBufferInfo()['Attributes'] + except pywintypes.error: + # stdout may be defined but not support + # GetConsoleScreenBufferInfo(), when called from subprocess or + # redirected. + raise ImportError() ansire = re.compile('\033\[([^m]*)m([^\033]*)(.*)', re.MULTILINE | re.DOTALL) def win32print(text, orig, **opts):