# HG changeset patch # User Pierre-Yves David <pierre-yves.da...@ens-lyon.org> # Date 1482370638 -3600 # Thu Dec 22 02:37:18 2016 +0100 # Node ID 93e658cd6e685593ddc94d2b46ba596b1bb0d143 # Parent 93992a625b7141ab5ba0a6cdd5db1aac3ab75361 # EXP-Topic color color: move '_effect_str' function into the core module
diff -r 93992a625b71 -r 93e658cd6e68 hgext/color.py --- a/hgext/color.py Thu Dec 22 02:34:22 2016 +0100 +++ b/hgext/color.py Thu Dec 22 02:37:18 2016 +0100 @@ -297,27 +297,6 @@ def _modesetup(ui, coloropt): return realmode return None -def _effect_str(effect): - '''Helper function for render_effects().''' - - bg = False - if effect.endswith('_background'): - bg = True - effect = effect[:-11] - try: - attr, val, termcode = color._terminfo_params[effect] - except KeyError: - return '' - if attr: - if termcode: - return termcode - else: - return curses.tigetstr(val) - elif bg: - return curses.tparm(curses.tigetstr('setab'), val) - else: - return curses.tparm(curses.tigetstr('setaf'), val) - def render_effects(text, effects): 'Wrap text in commands to turn on each effect.' if not text: @@ -327,9 +306,9 @@ def render_effects(text, effects): start = '\033[' + ';'.join(start) + 'm' stop = '\033[' + str(color._effects['none']) + 'm' else: - start = ''.join(_effect_str(effect) + start = ''.join(color._effect_str(effect) for effect in ['none'] + effects.split()) - stop = _effect_str('none') + stop = color._effect_str('none') return ''.join([start, text, stop]) class colorui(uimod.ui): diff -r 93992a625b71 -r 93e658cd6e68 mercurial/color.py --- a/mercurial/color.py Thu Dec 22 02:34:22 2016 +0100 +++ b/mercurial/color.py Thu Dec 22 02:37:18 2016 +0100 @@ -137,3 +137,24 @@ def valideffect(effect): return ((not _terminfo_params and effect in _effects) or (effect in _terminfo_params or effect[:-11] in _terminfo_params)) + +def _effect_str(effect): + '''Helper function for render_effects().''' + + bg = False + if effect.endswith('_background'): + bg = True + effect = effect[:-11] + try: + attr, val, termcode = _terminfo_params[effect] + except KeyError: + return '' + if attr: + if termcode: + return termcode + else: + return curses.tigetstr(val) + elif bg: + return curses.tparm(curses.tigetstr('setab'), val) + else: + return curses.tparm(curses.tigetstr('setaf'), val) _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel