changeset 12065:a8b1cb0b0ddb

color: handle more Windows console errors If your application is being built as a non-console application, stdout is not a valid handle and raises an exception: pywintypes.error: (6, 'DuplicateHandle', 'The handle is invalid.') Alternatively, non-console applications launched outside of a console will return None from GetStdHandle instead of raising an exception.
author Steve Borho <steve@borho.org>
date Fri, 27 Aug 2010 22:24:47 -0500
parents 6449be7b8a3b
children d01e28657429
files hgext/color.py
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Wed Aug 25 23:26:18 2010 +0100
+++ b/hgext/color.py	Fri Aug 27 22:24:47 2010 -0500
@@ -254,8 +254,10 @@
         'inverse': win32c.COMMON_LVB_REVERSE_VIDEO, # double-byte charsets only
     }
 
-    stdout = win32c.GetStdHandle(win32c.STD_OUTPUT_HANDLE)
     try:
+        stdout = win32c.GetStdHandle(win32c.STD_OUTPUT_HANDLE)
+        if stdout is None:
+            raise ImportError()
         origattr = stdout.GetConsoleScreenBufferInfo()['Attributes']
     except pywintypes.error:
         # stdout may be defined but not support