[PATCH STABLE] color: pass on key error for win32

Sean Farley sean.michael.farley at gmail.com
Fri Aug 1 13:09:12 CDT 2014


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1406916546 18000
#      Fri Aug 01 13:09:06 2014 -0500
# Branch stable
# Node ID d85e690bd86678be5b43ede85d9b7521190ae7e6
# Parent  27205c8335b06d8a2718b85c71adfaa3287cec35
color: pass on key error for win32

This is a quick fix for some consoles on windows (consoles that are not mingw
based) so that the debugcolor command doesn't throw a KeyError when effects
aren't supported (e.g. italic).

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -560,12 +560,16 @@ else:
 
         # determine console attributes based on labels
         for l in label.split():
             style = _styles.get(l, '')
             for effect in style.split():
-                attr = mapcolor(w32effects[effect], attr)
-
+                try:
+                    attr = mapcolor(w32effects[effect], attr)
+                except KeyError:
+                    # w32effects could not have certain attributes so we skip
+                    # them if not found
+                    pass
         # hack to ensure regexp finds data
         if not text.startswith('\033['):
             text = '\033[m' + text
 
         # Look for ANSI-like codes embedded in text


More information about the Mercurial-devel mailing list