# HG changeset patch # User Brodie Rao # Date 1228146322 18000 # Node ID 3fb5c142a9f073b27c5ea07a9ac4fb540640b3ed # Parent 03dd5511598552be027bbb9a34d21241cb8c42bf color: replace effect-specific reset control codes with general purpose one diff -r 03dd55115985 -r 3fb5c142a9f0 hgext/color.py --- a/hgext/color.py Tue Dec 02 10:13:52 2008 -0600 +++ b/hgext/color.py Mon Dec 01 10:45:22 2008 -0500 @@ -67,39 +67,34 @@ from mercurial.i18n import _ # start and stop parameters for effects -_effect_params = { 'none': (0, 0), - 'black': (30, 39), - 'red': (31, 39), - 'green': (32, 39), - 'yellow': (33, 39), - 'blue': (34, 39), - 'magenta': (35, 39), - 'cyan': (36, 39), - 'white': (37, 39), - 'bold': (1, 22), - 'italic': (3, 23), - 'underline': (4, 24), - 'inverse': (7, 27), - 'black_background': (40, 49), - 'red_background': (41, 49), - 'green_background': (42, 49), - 'yellow_background': (43, 49), - 'blue_background': (44, 49), - 'purple_background': (45, 49), - 'cyan_background': (46, 49), - 'white_background': (47, 49), } +_effect_params = {'none': 0, + 'black': 30, + 'red': 31, + 'green': 32, + 'yellow': 33, + 'blue': 34, + 'magenta': 35, + 'cyan': 36, + 'white': 37, + 'bold': 1, + 'italic': 3, + 'underline': 4, + 'inverse': 7, + 'black_background': 40, + 'red_background': 41, + 'green_background': 42, + 'yellow_background': 43, + 'blue_background': 44, + 'purple_background': 45, + 'cyan_background': 46, + 'white_background': 47} def render_effects(text, *effects): 'Wrap text in commands to turn on each effect.' - start = [ str(_effect_params['none'][0]) ] - stop = [] - for effect in effects: - start.append(str(_effect_params[effect][0])) - stop.append(str(_effect_params[effect][1])) - stop.append(str(_effect_params['none'][1])) + start = [str(_effect_params[e]) for e in ('none',) + effects] start = '\033[' + ';'.join(start) + 'm' - stop = '\033[' + ';'.join(stop) + 'm' - return start + text + stop + stop = '\033[' + str(_effect_params['none']) + 'm' + return ''.join([start, text, stop]) def colorstatus(orig, ui, repo, *pats, **opts): '''run the status command with colored output''' diff -r 03dd55115985 -r 3fb5c142a9f0 tests/test-diff-color.out --- a/tests/test-diff-color.out Tue Dec 02 10:13:52 2008 -0600 +++ b/tests/test-diff-color.out Mon Dec 01 10:45:22 2008 -0500 @@ -1,25 +1,25 @@ adding a % default context -diff -r cf9f4ba66af2 a ---- a/a -+++ b/a -@@ -2,7 +2,7 @@ +diff -r cf9f4ba66af2 a +--- a/a ++++ b/a +@@ -2,7 +2,7 @@ c a a --b -+dd +-b ++dd a a c % --unified=2 -diff -r cf9f4ba66af2 a ---- a/a -+++ b/a -@@ -3,5 +3,5 @@ +diff -r cf9f4ba66af2 a +--- a/a ++++ b/a +@@ -3,5 +3,5 @@ a a --b -+dd +-b ++dd a a diff -r 03dd55115985 -r 3fb5c142a9f0 tests/test-status-color.out --- a/tests/test-status-color.out Tue Dec 02 10:13:52 2008 -0600 +++ b/tests/test-status-color.out Mon Dec 01 10:45:22 2008 -0500 @@ -1,125 +1,125 @@ hg status in repo root: -? a/1/in_a_1 -? a/in_a -? b/1/in_b_1 -? b/2/in_b_2 -? b/in_b -? in_root +? a/1/in_a_1 +? a/in_a +? b/1/in_b_1 +? b/2/in_b_2 +? b/in_b +? in_root hg status . in repo root: -? a/1/in_a_1 -? a/in_a -? b/1/in_b_1 -? b/2/in_b_2 -? b/in_b -? in_root +? a/1/in_a_1 +? a/in_a +? b/1/in_b_1 +? b/2/in_b_2 +? b/in_b +? in_root hg status in a: -? a/1/in_a_1 -? a/in_a -? b/1/in_b_1 -? b/2/in_b_2 -? b/in_b -? in_root +? a/1/in_a_1 +? a/in_a +? b/1/in_b_1 +? b/2/in_b_2 +? b/in_b +? in_root hg status . in a: -? 1/in_a_1 -? in_a +? 1/in_a_1 +? in_a hg status .. in a: -? 1/in_a_1 -? in_a -? ../b/1/in_b_1 -? ../b/2/in_b_2 -? ../b/in_b -? ../in_root +? 1/in_a_1 +? in_a +? ../b/1/in_b_1 +? ../b/2/in_b_2 +? ../b/in_b +? ../in_root hg status in b: -? a/1/in_a_1 -? a/in_a -? b/1/in_b_1 -? b/2/in_b_2 -? b/in_b -? in_root +? a/1/in_a_1 +? a/in_a +? b/1/in_b_1 +? b/2/in_b_2 +? b/in_b +? in_root hg status . in b: -? 1/in_b_1 -? 2/in_b_2 -? in_b +? 1/in_b_1 +? 2/in_b_2 +? in_b hg status .. in b: -? ../a/1/in_a_1 -? ../a/in_a -? 1/in_b_1 -? 2/in_b_2 -? in_b -? ../in_root +? ../a/1/in_a_1 +? ../a/in_a +? 1/in_b_1 +? 2/in_b_2 +? in_b +? ../in_root hg status in a/1: -? a/1/in_a_1 -? a/in_a -? b/1/in_b_1 -? b/2/in_b_2 -? b/in_b -? in_root +? a/1/in_a_1 +? a/in_a +? b/1/in_b_1 +? b/2/in_b_2 +? b/in_b +? in_root hg status . in a/1: -? in_a_1 +? in_a_1 hg status .. in a/1: -? in_a_1 -? ../in_a +? in_a_1 +? ../in_a hg status in b/1: -? a/1/in_a_1 -? a/in_a -? b/1/in_b_1 -? b/2/in_b_2 -? b/in_b -? in_root +? a/1/in_a_1 +? a/in_a +? b/1/in_b_1 +? b/2/in_b_2 +? b/in_b +? in_root hg status . in b/1: -? in_b_1 +? in_b_1 hg status .. in b/1: -? in_b_1 -? ../2/in_b_2 -? ../in_b +? in_b_1 +? ../2/in_b_2 +? ../in_b hg status in b/2: -? a/1/in_a_1 -? a/in_a -? b/1/in_b_1 -? b/2/in_b_2 -? b/in_b -? in_root +? a/1/in_a_1 +? a/in_a +? b/1/in_b_1 +? b/2/in_b_2 +? b/in_b +? in_root hg status . in b/2: -? in_b_2 +? in_b_2 hg status .. in b/2: -? ../1/in_b_1 -? in_b_2 -? ../in_b +? ../1/in_b_1 +? in_b_2 +? ../in_b adding .hgignore adding deleted adding modified adding removed hg status: -A added -R removed -! deleted -? unknown +A added +R removed +! deleted +? unknown hg status modified added removed deleted unknown never-existed ignored: never-existed: No such file or directory -A added -R removed -! deleted -? unknown +A added +R removed +! deleted +? unknown hg status -C: -A added -A copied - modified -R removed -! deleted -? unknown +A added +A copied + modified +R removed +! deleted +? unknown hg status -A: -A added -A copied - modified -R removed -! deleted -? unknown -I ignored -C .hgignore -C modified +A added +A copied + modified +R removed +! deleted +? unknown +I ignored +C .hgignore +C modified hg status ignoreddir/file: hg status -i ignoreddir/file: -I ignoreddir/file +I ignoreddir/file adding .hgignore adding deleted adding modified