Mercurial > public > mercurial-scm > hg
diff mercurial/color.py @ 30972:a3c7e42c7a1f
color: move '_effect_str' function into the core module
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 22 Dec 2016 02:37:18 +0100 |
parents | bb6385882cfa |
children | e5363cb96233 |
line wrap: on
line diff
--- 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 @@ 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)