[PATCH] color: don't blow up if configured with unknown color
Greg Ward
greg-hg at gerg.ca
Tue Jun 23 21:49:05 CDT 2009
# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1245811720 14400
# Node ID 9de8ccf861370259326036e267025d6661734b58
# Parent 5e6a6fb10a77f1a55e0f9acd49ee5aea6004dc78
color: don't blow up if configured with unknown color.
(I wanted to print a warning in this case, but getting a ui object down
to where the error happens looks rather tricky, so I punted.)
diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -88,9 +88,17 @@
def render_effects(text, effects):
'Wrap text in commands to turn on each effect.'
- start = [str(_effect_params[e]) for e in ['none'] + effects]
+ noeffect = str(_effect_params['none'])
+ start = [noeffect]
+ for e in effects:
+ try:
+ start.append(str(_effect_params[e]))
+ except KeyError:
+ # argh: getting a ui object in here looks quite tricky. punt.
+ #ui.warn(_("unknown color/effect %r (ignoring)") % e)
+ pass
start = '\033[' + ';'.join(start) + 'm'
- stop = '\033[' + str(_effect_params['none']) + 'm'
+ stop = '\033[' + noeffect + 'm'
return ''.join([start, text, stop])
def colorstatus(orig, ui, repo, *pats, **opts):
diff --git a/tests/test-status-color b/tests/test-status-color
--- a/tests/test-status-color
+++ b/tests/test-status-color
@@ -61,6 +61,9 @@
rm deleted
hg copy modified copied
+echo "% test unknown color"
+hg --config color.status.modified=periwinkle status --color=always
+
# Run status with 2 different flags.
# Check if result is the same or different.
# If result is not as expected, raise error
diff --git a/tests/test-status-color.out b/tests/test-status-color.out
--- a/tests/test-status-color.out
+++ b/tests/test-status-color.out
@@ -124,3 +124,10 @@
adding deleted
adding modified
adding removed
+% test unknown color
+[0mM modified[0m
+[0;32;1mA added[0m
+[0;32;1mA copied[0m
+[0;31;1mR removed[0m
+[0;36;1;4m! deleted[0m
+[0;35;1;4m? unknown[0m
More information about the Mercurial-devel
mailing list