Patchwork [1,of,7] color: move 'debugcolor' into the 'debugcommands' modules

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 28, 2017, 7:25 p.m.
Message ID <7e3d17f7acca8f1f1ff7.1488309941@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/18842/
State Accepted
Headers show

Comments

Pierre-Yves David - Feb. 28, 2017, 7:25 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1487698897 -3600
#      Tue Feb 21 18:41:37 2017 +0100
# Node ID 7e3d17f7acca8f1f1ff7d15864990201a528e1cd
# Parent  6483e49204ee7cb34727534c6dec334c14097d5f
# EXP-Topic color
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.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -164,21 +164,11 @@  If ``pagermode`` is not defined, the ``m
 
 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 @@  def extsetup(ui):
             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')
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -31,6 +31,7 @@  from . import (
     bundle2,
     changegroup,
     cmdutil,
+    color,
     commands,
     context,
     dagparser,
@@ -344,6 +345,51 @@  def debugcheckstate(ui, repo):
         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"""
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -73,6 +73,7 @@  Show debug commands if there are no othe
   debugbuilddag
   debugbundle
   debugcheckstate
+  debugcolor
   debugcommands
   debugcomplete
   debugconfig
@@ -244,6 +245,7 @@  Show all commands + options
   debugbuilddag: mergeable-file, overwritten-file, new-file
   debugbundle: all, spec
   debugcheckstate: 
+  debugcolor: style
   debugcommands: 
   debugcomplete: options
   debugcreatestreamclonebundle: 
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -864,6 +864,7 @@  Test list of internal help commands
    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