# HG changeset patch # User Idan Kamara # Date 2011-04-09 20:53:23 # Node ID 67f20625703fc358e53a6e7cf3102ccffba5bb2b # Parent 55f4941f98c8bf9cf9fc4ca5f1d7c525ef5e3562 color: reset win32 console color in a finally block diff --git a/hgext/color.py b/hgext/color.py --- a/hgext/color.py +++ b/hgext/color.py @@ -349,13 +349,15 @@ else: # 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)