changeset 13919:67f20625703f

color: reset win32 console color in a finally block
author Idan Kamara <idankk86@gmail.com>
date Sat, 09 Apr 2011 23:53:23 +0300
parents 55f4941f98c8
children 332e400764e5
files hgext/color.py
diffstat 1 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Sat Apr 09 15:52:19 2011 -0500
+++ b/hgext/color.py	Sat Apr 09 23:53:23 2011 +0300
@@ -349,13 +349,15 @@
 
         # Look for ANSI-like codes embedded in text
         m = re.match(ansire, text)
-        while m:
-            for sattr in m.group(1).split(';'):
-                if sattr:
-                    attr = mapcolor(int(sattr), attr)
-            _kernel32.SetConsoleTextAttribute(stdout, attr)
-            orig(m.group(2), **opts)
-            m = re.match(ansire, m.group(3))
 
-        # Explicity reset original attributes
-        _kernel32.SetConsoleTextAttribute(stdout, origattr)
+        try:
+            while m:
+                for sattr in m.group(1).split(';'):
+                    if sattr:
+                        attr = mapcolor(int(sattr), attr)
+                _kernel32.SetConsoleTextAttribute(stdout, attr)
+                orig(m.group(2), **opts)
+                m = re.match(ansire, m.group(3))
+        finally:
+            # Explicity reset original attributes
+            _kernel32.SetConsoleTextAttribute(stdout, origattr)