diff mercurial/color.py @ 30973:e5363cb96233

color: move the '_render_effects' function to the core module
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Thu, 22 Dec 2016 02:38:53 +0100
parents a3c7e42c7a1f
children a0bde5ec3a46
line wrap: on
line diff
--- a/mercurial/color.py	Thu Dec 22 02:37:18 2016 +0100
+++ b/mercurial/color.py	Thu Dec 22 02:38:53 2016 +0100
@@ -158,3 +158,17 @@
         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:
+        return text
+    if not _terminfo_params:
+        start = [str(_effects[e]) for e in ['none'] + effects.split()]
+        start = '\033[' + ';'.join(start) + 'm'
+        stop = '\033[' + str(_effects['none']) + 'm'
+    else:
+        start = ''.join(_effect_str(effect)
+                        for effect in ['none'] + effects.split())
+        stop = _effect_str('none')
+    return ''.join([start, text, stop])