Patchwork [V2,STABLE] color: pass on key error for win32 (issue4298)

login
register
mail settings
Submitter Sean Farley
Date Aug. 3, 2014, 8:17 p.m.
Message ID <171182895818995f28c4.1407097074@laptop.local>
Download mbox | patch
Permalink /patch/5246/
State Accepted
Headers show

Comments

Sean Farley - Aug. 3, 2014, 8:17 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1406916546 18000
#      Fri Aug 01 13:09:06 2014 -0500
# Branch stable
# Node ID 171182895818995f28c447dc1a0b8d3379ff5427
# Parent  27205c8335b06d8a2718b85c71adfaa3287cec35
color: pass on key error for win32 (issue4298)

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).
Matt Mackall - Aug. 4, 2014, 12:36 a.m.
On Sun, 2014-08-03 at 15:17 -0500, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1406916546 18000
> #      Fri Aug 01 13:09:06 2014 -0500
> # Branch stable
> # Node ID 171182895818995f28c447dc1a0b8d3379ff5427
> # Parent  27205c8335b06d8a2718b85c71adfaa3287cec35
> color: pass on key error for win32 (issue4298)

Queued for stable, thanks.

Patch

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