Patchwork [6,of,8,simple] color: move configstyles into the core module

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 15, 2017, 11:06 a.m.
Message ID <93992a625b7141ab5ba0.1487156778@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18509/
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 1482370462 -3600
#      Thu Dec 22 02:34:22 2016 +0100
# Node ID 93992a625b7141ab5ba0a6cdd5db1aac3ab75361
# Parent  07618a3840fbce3ab1084765d94ac8d7a9380ff8
# EXP-Topic color
color: move configstyles into the core module

The extension is getting thinner as we speak!

Patch

diff -r 07618a3840fb -r 93992a625b71 hgext/color.py
--- a/hgext/color.py	Thu Dec 22 02:30:03 2016 +0100
+++ b/hgext/color.py	Thu Dec 22 02:34:22 2016 +0100
@@ -332,22 +332,6 @@  def render_effects(text, effects):
         stop = _effect_str('none')
     return ''.join([start, text, stop])
 
-def configstyles(ui):
-    for status, cfgeffects in ui.configitems('color'):
-        if '.' not in status or status.startswith(('color.', 'terminfo.')):
-            continue
-        cfgeffects = ui.configlist('color', status)
-        if cfgeffects:
-            good = []
-            for e in cfgeffects:
-                if color.valideffect(e):
-                    good.append(e)
-                else:
-                    ui.warn(_("ignoring unknown color/effect %r "
-                              "(configured in color.%s)\n")
-                            % (e, status))
-            color._styles[status] = ' '.join(good)
-
 class colorui(uimod.ui):
     _colormode = 'ansi'
     def write(self, *args, **opts):
@@ -420,7 +404,7 @@  def uisetup(ui):
         mode = _modesetup(ui_, opts['color'])
         colorui._colormode = mode
         if mode and mode != 'debug':
-            configstyles(ui_)
+            color.configstyles(ui_)
         return orig(ui_, opts, cmd, cmdfunc)
     def colorgit(orig, gitsub, commands, env=None, stream=False, cwd=None):
         if gitsub.ui._colormode and len(commands) and commands[0] == "diff":
diff -r 07618a3840fb -r 93992a625b71 mercurial/color.py
--- a/mercurial/color.py	Thu Dec 22 02:30:03 2016 +0100
+++ b/mercurial/color.py	Thu Dec 22 02:34:22 2016 +0100
@@ -7,6 +7,8 @@ 
 
 from __future__ import absolute_import
 
+from .i18n import _
+
 try:
     import curses
     # Mapping from effect name to terminfo attribute name (or raw code) or
@@ -114,6 +116,22 @@  except ImportError:
 def loadcolortable(ui, extname, colortable):
     _styles.update(colortable)
 
+def configstyles(ui):
+    for status, cfgeffects in ui.configitems('color'):
+        if '.' not in status or status.startswith(('color.', 'terminfo.')):
+            continue
+        cfgeffects = ui.configlist('color', status)
+        if cfgeffects:
+            good = []
+            for e in cfgeffects:
+                if valideffect(e):
+                    good.append(e)
+                else:
+                    ui.warn(_("ignoring unknown color/effect %r "
+                              "(configured in color.%s)\n")
+                            % (e, status))
+            _styles[status] = ' '.join(good)
+
 def valideffect(effect):
     'Determine if the effect is valid or not.'
     return ((not _terminfo_params and effect in _effects)