color: move hgext.color._styles to mercurial.color.style
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Fri, 18 Nov 2016 18:09:36 +0100
changeset 30652 1ec42bdd7874
parent 30651 27e48410380d
child 30653 b2be4ccaff1d
color: move hgext.color._styles to mercurial.color.style This is small first step to start moving the color infrastructure into core. The current code of the color extensions is full of strange and debatable things, we'll clean it up in the process as having things into core help the cleaning. Moving _style was the simplest sensible move that is possible. It will also help cleaning up the extension setup process in a later changesets.
hgext/color.py
mercurial/color.py
--- a/hgext/color.py	Fri Nov 18 18:29:19 2016 +0100
+++ b/hgext/color.py	Fri Nov 18 18:09:36 2016 +0100
@@ -167,6 +167,7 @@
 from mercurial.i18n import _
 from mercurial import (
     cmdutil,
+    color,
     commands,
     dispatch,
     encoding,
@@ -323,61 +324,6 @@
 except ImportError:
     _terminfo_params = {}
 
-_styles = {'grep.match': 'red bold',
-           'grep.linenumber': 'green',
-           'grep.rev': 'green',
-           'grep.change': 'green',
-           'grep.sep': 'cyan',
-           'grep.filename': 'magenta',
-           'grep.user': 'magenta',
-           'grep.date': 'magenta',
-           'bookmarks.active': 'green',
-           'branches.active': 'none',
-           'branches.closed': 'black bold',
-           'branches.current': 'green',
-           'branches.inactive': 'none',
-           'diff.changed': 'white',
-           'diff.deleted': 'red',
-           'diff.diffline': 'bold',
-           'diff.extended': 'cyan bold',
-           'diff.file_a': 'red bold',
-           'diff.file_b': 'green bold',
-           'diff.hunk': 'magenta',
-           'diff.inserted': 'green',
-           'diff.tab': '',
-           'diff.trailingwhitespace': 'bold red_background',
-           'changeset.public' : '',
-           'changeset.draft' : '',
-           'changeset.secret' : '',
-           'diffstat.deleted': 'red',
-           'diffstat.inserted': 'green',
-           'histedit.remaining': 'red bold',
-           'ui.prompt': 'yellow',
-           'log.changeset': 'yellow',
-           'patchbomb.finalsummary': '',
-           'patchbomb.from': 'magenta',
-           'patchbomb.to': 'cyan',
-           'patchbomb.subject': 'green',
-           'patchbomb.diffstats': '',
-           'rebase.rebased': 'blue',
-           'rebase.remaining': 'red bold',
-           'resolve.resolved': 'green bold',
-           'resolve.unresolved': 'red bold',
-           'shelve.age': 'cyan',
-           'shelve.newest': 'green bold',
-           'shelve.name': 'blue bold',
-           'status.added': 'green bold',
-           'status.clean': 'none',
-           'status.copied': 'none',
-           'status.deleted': 'cyan bold underline',
-           'status.ignored': 'black bold',
-           'status.modified': 'blue bold',
-           'status.removed': 'red bold',
-           'status.unknown': 'magenta bold underline',
-           'tags.normal': 'green',
-           'tags.local': 'black bold'}
-
-
 def _effect_str(effect):
     '''Helper function for render_effects().'''
 
@@ -415,7 +361,7 @@
 
 def extstyles():
     for name, ext in extensions.extensions():
-        _styles.update(getattr(ext, 'colortable', {}))
+        color._styles.update(getattr(ext, 'colortable', {}))
 
 def valideffect(effect):
     'Determine if the effect is valid or not.'
@@ -440,7 +386,7 @@
                     ui.warn(_("ignoring unknown color/effect %r "
                               "(configured in color.%s)\n")
                             % (e, status))
-            _styles[status] = ' '.join(good)
+            color._styles[status] = ' '.join(good)
 
 class colorui(uimod.ui):
     _colormode = 'ansi'
@@ -493,7 +439,7 @@
 
         effects = []
         for l in label.split():
-            s = _styles.get(l, '')
+            s = color._styles.get(l, '')
             if s:
                 effects.append(s)
             elif valideffect(l):
@@ -546,31 +492,31 @@
         return _debugdisplaycolor(ui)
 
 def _debugdisplaycolor(ui):
-    oldstyle = _styles.copy()
+    oldstyle = color._styles.copy()
     try:
-        _styles.clear()
+        color._styles.clear()
         for effect in _effects.keys():
-            _styles[effect] = effect
+            color._styles[effect] = effect
         if _terminfo_params:
             for k, v in ui.configitems('color'):
                 if k.startswith('color.'):
-                    _styles[k] = k[6:]
+                    color._styles[k] = k[6:]
                 elif k.startswith('terminfo.'):
-                    _styles[k] = k[9:]
+                    color._styles[k] = k[9:]
         ui.write(_('available colors:\n'))
         # sort label with a '_' after the other to group '_background' entry.
-        items = sorted(_styles.items(),
+        items = sorted(color._styles.items(),
                        key=lambda i: ('_' in i[0], i[0], i[1]))
         for colorname, label in items:
             ui.write(('%s\n') % colorname, label=label)
     finally:
-        _styles.clear()
-        _styles.update(oldstyle)
+        color._styles.clear()
+        color._styles.update(oldstyle)
 
 def _debugdisplaystyle(ui):
     ui.write(_('available style:\n'))
-    width = max(len(s) for s in _styles)
-    for label, effects in sorted(_styles.items()):
+    width = max(len(s) for s in color._styles)
+    for label, effects in sorted(color._styles.items()):
         ui.write('%s' % label, label=label)
         if effects:
             # 50
@@ -687,7 +633,7 @@
 
         # determine console attributes based on labels
         for l in label.split():
-            style = _styles.get(l, '')
+            style = color._styles.get(l, '')
             for effect in style.split():
                 try:
                     attr = mapcolor(w32effects[effect], attr)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/color.py	Fri Nov 18 18:09:36 2016 +0100
@@ -0,0 +1,62 @@
+# utility for color output for Mercurial commands
+#
+# Copyright (C) 2007 Kevin Christen <kevin.christen@gmail.com> and other
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+from __future__ import absolute_import
+
+_styles = {'grep.match': 'red bold',
+           'grep.linenumber': 'green',
+           'grep.rev': 'green',
+           'grep.change': 'green',
+           'grep.sep': 'cyan',
+           'grep.filename': 'magenta',
+           'grep.user': 'magenta',
+           'grep.date': 'magenta',
+           'bookmarks.active': 'green',
+           'branches.active': 'none',
+           'branches.closed': 'black bold',
+           'branches.current': 'green',
+           'branches.inactive': 'none',
+           'diff.changed': 'white',
+           'diff.deleted': 'red',
+           'diff.diffline': 'bold',
+           'diff.extended': 'cyan bold',
+           'diff.file_a': 'red bold',
+           'diff.file_b': 'green bold',
+           'diff.hunk': 'magenta',
+           'diff.inserted': 'green',
+           'diff.tab': '',
+           'diff.trailingwhitespace': 'bold red_background',
+           'changeset.public' : '',
+           'changeset.draft' : '',
+           'changeset.secret' : '',
+           'diffstat.deleted': 'red',
+           'diffstat.inserted': 'green',
+           'histedit.remaining': 'red bold',
+           'ui.prompt': 'yellow',
+           'log.changeset': 'yellow',
+           'patchbomb.finalsummary': '',
+           'patchbomb.from': 'magenta',
+           'patchbomb.to': 'cyan',
+           'patchbomb.subject': 'green',
+           'patchbomb.diffstats': '',
+           'rebase.rebased': 'blue',
+           'rebase.remaining': 'red bold',
+           'resolve.resolved': 'green bold',
+           'resolve.unresolved': 'red bold',
+           'shelve.age': 'cyan',
+           'shelve.newest': 'green bold',
+           'shelve.name': 'blue bold',
+           'status.added': 'green bold',
+           'status.clean': 'none',
+           'status.copied': 'none',
+           'status.deleted': 'cyan bold underline',
+           'status.ignored': 'black bold',
+           'status.modified': 'blue bold',
+           'status.removed': 'red bold',
+           'status.unknown': 'magenta bold underline',
+           'tags.normal': 'green',
+           'tags.local': 'black bold'}