# HG changeset patch # User Patrick Mezard # Date 2010-04-23 12:29:44 # Node ID 9fb09fc3ea3c28658133e6bd70f3abe6f8ec3612 # Parent f2340d699e79cefbc66630834465967255d2f6eb color: handle non-standard stdout on win32 diff --git a/hgext/color.py b/hgext/color.py --- a/hgext/color.py +++ b/hgext/color.py @@ -217,7 +217,7 @@ commands.globalopts.append(('', 'color', _("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 @@ try: } 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):