##// END OF EJS Templates
color: insert color code after every "\e[0m" (issue5413)...
Yuya Nishihara -
r31518:43d6ef65 default
parent child Browse files
Show More
@@ -296,6 +296,23 b' def _effect_str(ui, effect):'
296 296 else:
297 297 return curses.tparm(curses.tigetstr('setaf'), val)
298 298
299 def _mergeeffects(text, start, stop):
300 """Insert start sequence at every occurrence of stop sequence
301
302 >>> s = _mergeeffects('cyan', '[C]', '|')
303 >>> s = _mergeeffects(s + 'yellow', '[Y]', '|')
304 >>> s = _mergeeffects('ma' + s + 'genta', '[M]', '|')
305 >>> s = _mergeeffects('red' + s, '[R]', '|')
306 >>> s
307 '[R]red[M]ma[Y][C]cyan|[R][M][Y]yellow|[R][M]genta|'
308 """
309 parts = []
310 for t in text.split(stop):
311 if not t:
312 continue
313 parts.extend([start, t, stop])
314 return ''.join(parts)
315
299 316 def _render_effects(ui, text, effects):
300 317 'Wrap text in commands to turn on each effect.'
301 318 if not text:
@@ -308,7 +325,7 b' def _render_effects(ui, text, effects):'
308 325 start = [str(_effects[e]) for e in ['none'] + effects.split()]
309 326 start = '\033[' + ';'.join(start) + 'm'
310 327 stop = '\033[' + str(_effects['none']) + 'm'
311 return ''.join([start, text, stop])
328 return _mergeeffects(text, start, stop)
312 329
313 330 def colorlabel(ui, msg, label):
314 331 """add color control code according to the mode"""
@@ -3348,6 +3348,12 b' color effect can be specified without qu'
3348 3348 $ hg log --color=always -l 1 --template '{label(red, "text\n")}'
3349 3349 \x1b[0;31mtext\x1b[0m (esc)
3350 3350
3351 color effects can be nested (issue5413)
3352
3353 $ hg debugtemplate --color=always \
3354 > '{label(red, "red{label(magenta, "ma{label(cyan, "cyan")}{label(yellow, "yellow")}genta")}")}\n'
3355 \x1b[0;31mred\x1b[0;35mma\x1b[0;36mcyan\x1b[0m\x1b[0;31m\x1b[0;35m\x1b[0;33myellow\x1b[0m\x1b[0;31m\x1b[0;35mgenta\x1b[0m (esc)
3356
3351 3357 label should be no-op if color is disabled:
3352 3358
3353 3359 $ hg log --color=never -l 1 --template '{label(red, "text\n")}'
@@ -23,6 +23,7 b' def testmod(name, optionflags=0, testtar'
23 23
24 24 testmod('mercurial.changegroup')
25 25 testmod('mercurial.changelog')
26 testmod('mercurial.color')
26 27 testmod('mercurial.config')
27 28 testmod('mercurial.dagparser', optionflags=doctest.NORMALIZE_WHITESPACE)
28 29 testmod('mercurial.dispatch')
General Comments 0
You need to be logged in to leave comments. Login now