Patchwork [8,of,8,simple] color: move the '_render_effects' function to the core module

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 15, 2017, 11:06 a.m.
Message ID <f0f04ac8d4b17345b537.1487156780@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18507/
State Accepted
Delegated to: Martin von Zweigbergk
Headers show

Comments

Pierre-Yves David - Feb. 15, 2017, 11:06 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1482370733 -3600
#      Thu Dec 22 02:38:53 2016 +0100
# Node ID f0f04ac8d4b17345b5375e4b11d895e7c22eb6ab
# Parent  93e658cd6e685593ddc94d2b46ba596b1bb0d143
# EXP-Topic color
color: move the '_render_effects' function to the core module
via Mercurial-devel - Feb. 15, 2017, 10:17 p.m.
On Wed, Feb 15, 2017 at 3:06 AM, Pierre-Yves David
<pierre-yves.david@ens-lyon.org> wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1482370733 -3600
> #      Thu Dec 22 02:38:53 2016 +0100
> # Node ID f0f04ac8d4b17345b5375e4b11d895e7c22eb6ab
> # Parent  93e658cd6e685593ddc94d2b46ba596b1bb0d143
> # EXP-Topic color
> color: move the '_render_effects' function to the core module

Queued, thanks.

Patch

diff -r 93e658cd6e68 -r f0f04ac8d4b1 hgext/color.py
--- a/hgext/color.py	Thu Dec 22 02:37:18 2016 +0100
+++ b/hgext/color.py	Thu Dec 22 02:38:53 2016 +0100
@@ -297,20 +297,6 @@  def _modesetup(ui, coloropt):
         return realmode
     return None
 
-def render_effects(text, effects):
-    'Wrap text in commands to turn on each effect.'
-    if not text:
-        return text
-    if not color._terminfo_params:
-        start = [str(color._effects[e]) for e in ['none'] + effects.split()]
-        start = '\033[' + ';'.join(start) + 'm'
-        stop = '\033[' + str(color._effects['none']) + 'm'
-    else:
-        start = ''.join(color._effect_str(effect)
-                        for effect in ['none'] + effects.split())
-        stop = color._effect_str('none')
-    return ''.join([start, text, stop])
-
 class colorui(uimod.ui):
     _colormode = 'ansi'
     def write(self, *args, **opts):
@@ -369,7 +355,7 @@  class colorui(uimod.ui):
                 effects.append(l)
         effects = ' '.join(effects)
         if effects:
-            return '\n'.join([render_effects(line, effects)
+            return '\n'.join([color._render_effects(line, effects)
                               for line in msg.split('\n')])
         return msg
 
diff -r 93e658cd6e68 -r f0f04ac8d4b1 mercurial/color.py
--- 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 @@  def _effect_str(effect):
         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])