changeset 31135:c4e8fa2b1c40

color: move 'debugcolor' into the 'debugcommands' modules This is the last bits we needed to move out of the extensions. 'hgext/color.py' now only contains logic to changes the default color behavior to 'auto'. However, more cleanups are on the way and we need to document the new config directly in core.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 21 Feb 2017 18:41:37 +0100
parents 13bbcd56c57a
children 8fc55bbd2235
files hgext/color.py mercurial/debugcommands.py tests/test-completion.t tests/test-help.t
diffstat 4 files changed, 50 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Tue Feb 28 11:13:25 2017 -0800
+++ b/hgext/color.py	Tue Feb 21 18:41:37 2017 +0100
@@ -164,21 +164,11 @@
 
 from __future__ import absolute_import
 
-try:
-    import curses
-    curses.COLOR_BLACK # force import
-except ImportError:
-    curses = None
-
-from mercurial.i18n import _
 from mercurial import (
-    cmdutil,
     color,
-    commands,
+    commands
 )
 
-cmdtable = {}
-command = cmdutil.command(cmdtable)
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
@@ -194,48 +184,3 @@
             new = entry[:3] + patch + entry[4:]
             commands.globalopts[idx] = new
             break
-
-@command('debugcolor',
-        [('', 'style', None, _('show all configured styles'))],
-        'hg debugcolor')
-def debugcolor(ui, repo, **opts):
-    """show available color, effects or style"""
-    ui.write(('color mode: %s\n') % ui._colormode)
-    if opts.get('style'):
-        return _debugdisplaystyle(ui)
-    else:
-        return _debugdisplaycolor(ui)
-
-def _debugdisplaycolor(ui):
-    oldstyle = ui._styles.copy()
-    try:
-        ui._styles.clear()
-        for effect in color._effects.keys():
-            ui._styles[effect] = effect
-        if ui._terminfoparams:
-            for k, v in ui.configitems('color'):
-                if k.startswith('color.'):
-                    ui._styles[k] = k[6:]
-                elif k.startswith('terminfo.'):
-                    ui._styles[k] = k[9:]
-        ui.write(_('available colors:\n'))
-        # sort label with a '_' after the other to group '_background' entry.
-        items = sorted(ui._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:
-        ui._styles.clear()
-        ui._styles.update(oldstyle)
-
-def _debugdisplaystyle(ui):
-    ui.write(_('available style:\n'))
-    width = max(len(s) for s in ui._styles)
-    for label, effects in sorted(ui._styles.items()):
-        ui.write('%s' % label, label=label)
-        if effects:
-            # 50
-            ui.write(': ')
-            ui.write(' ' * (max(0, width - len(label))))
-            ui.write(', '.join(ui.label(e, e) for e in effects.split()))
-        ui.write('\n')
--- a/mercurial/debugcommands.py	Tue Feb 28 11:13:25 2017 -0800
+++ b/mercurial/debugcommands.py	Tue Feb 21 18:41:37 2017 +0100
@@ -31,6 +31,7 @@
     bundle2,
     changegroup,
     cmdutil,
+    color,
     commands,
     context,
     dagparser,
@@ -344,6 +345,51 @@
         error = _(".hg/dirstate inconsistent with current parent's manifest")
         raise error.Abort(error)
 
+@command('debugcolor',
+        [('', 'style', None, _('show all configured styles'))],
+        'hg debugcolor')
+def debugcolor(ui, repo, **opts):
+    """show available color, effects or style"""
+    ui.write(('color mode: %s\n') % ui._colormode)
+    if opts.get('style'):
+        return _debugdisplaystyle(ui)
+    else:
+        return _debugdisplaycolor(ui)
+
+def _debugdisplaycolor(ui):
+    oldstyle = ui._styles.copy()
+    try:
+        ui._styles.clear()
+        for effect in color._effects.keys():
+            ui._styles[effect] = effect
+        if ui._terminfoparams:
+            for k, v in ui.configitems('color'):
+                if k.startswith('color.'):
+                    ui._styles[k] = k[6:]
+                elif k.startswith('terminfo.'):
+                    ui._styles[k] = k[9:]
+        ui.write(_('available colors:\n'))
+        # sort label with a '_' after the other to group '_background' entry.
+        items = sorted(ui._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:
+        ui._styles.clear()
+        ui._styles.update(oldstyle)
+
+def _debugdisplaystyle(ui):
+    ui.write(_('available style:\n'))
+    width = max(len(s) for s in ui._styles)
+    for label, effects in sorted(ui._styles.items()):
+        ui.write('%s' % label, label=label)
+        if effects:
+            # 50
+            ui.write(': ')
+            ui.write(' ' * (max(0, width - len(label))))
+            ui.write(', '.join(ui.label(e, e) for e in effects.split()))
+        ui.write('\n')
+
 @command('debugcommands', [], _('[COMMAND]'), norepo=True)
 def debugcommands(ui, cmd='', *args):
     """list all available commands and options"""
--- a/tests/test-completion.t	Tue Feb 28 11:13:25 2017 -0800
+++ b/tests/test-completion.t	Tue Feb 21 18:41:37 2017 +0100
@@ -73,6 +73,7 @@
   debugbuilddag
   debugbundle
   debugcheckstate
+  debugcolor
   debugcommands
   debugcomplete
   debugconfig
@@ -244,6 +245,7 @@
   debugbuilddag: mergeable-file, overwritten-file, new-file
   debugbundle: all, spec
   debugcheckstate: 
+  debugcolor: style
   debugcommands: 
   debugcomplete: options
   debugcreatestreamclonebundle: 
--- a/tests/test-help.t	Tue Feb 28 11:13:25 2017 -0800
+++ b/tests/test-help.t	Tue Feb 21 18:41:37 2017 +0100
@@ -864,6 +864,7 @@
    debugbundle   lists the contents of a bundle
    debugcheckstate
                  validate the correctness of the current dirstate
+   debugcolor    show available color, effects or style
    debugcommands
                  list all available commands and options
    debugcomplete