Mercurial > hg
comparison hgext/color.py @ 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 | 1ce0e80799c0 |
children | e0f07847f8de |
comparison
equal
deleted
inserted
replaced
13918:55f4941f98c8 | 13919:67f20625703f |
---|---|
347 if not text.startswith('\033['): | 347 if not text.startswith('\033['): |
348 text = '\033[m' + text | 348 text = '\033[m' + text |
349 | 349 |
350 # Look for ANSI-like codes embedded in text | 350 # Look for ANSI-like codes embedded in text |
351 m = re.match(ansire, text) | 351 m = re.match(ansire, text) |
352 while m: | 352 |
353 for sattr in m.group(1).split(';'): | 353 try: |
354 if sattr: | 354 while m: |
355 attr = mapcolor(int(sattr), attr) | 355 for sattr in m.group(1).split(';'): |
356 _kernel32.SetConsoleTextAttribute(stdout, attr) | 356 if sattr: |
357 orig(m.group(2), **opts) | 357 attr = mapcolor(int(sattr), attr) |
358 m = re.match(ansire, m.group(3)) | 358 _kernel32.SetConsoleTextAttribute(stdout, attr) |
359 | 359 orig(m.group(2), **opts) |
360 # Explicity reset original attributes | 360 m = re.match(ansire, m.group(3)) |
361 _kernel32.SetConsoleTextAttribute(stdout, origattr) | 361 finally: |
362 # Explicity reset original attributes | |
363 _kernel32.SetConsoleTextAttribute(stdout, origattr) |