[PATCH 08 of 35] color: declare command using decorator

Gregory Szorc gregory.szorc at gmail.com
Mon May 5 00:51:13 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1399265290 25200
#      Sun May 04 21:48:10 2014 -0700
# Branch stable
# Node ID 1ca8d982041c4161a9fd5c3d4d71568ca9115b99
# Parent  97f38eec7d53e86e7865f6add1513ae2b3e6cf89
color: declare command using decorator

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -106,20 +106,22 @@ terminfo mode, for example), set the fol
   mode = terminfo
 
 Any value other than 'ansi', 'win32', 'terminfo', or 'auto' will
 disable color.
 '''
 
 import os
 
-from mercurial import commands, dispatch, extensions, ui as uimod, util
+from mercurial import cmdutil, commands, dispatch, extensions, ui as uimod, util
 from mercurial import templater, error
 from mercurial.i18n import _
 
+cmdtable = {}
+command = cmdutil.command(cmdtable)
 testedwith = 'internal'
 
 # start and stop parameters for effects
 _effects = {'none': 0, 'black': 30, 'red': 31, 'green': 32, 'yellow': 33,
             'blue': 34, 'magenta': 35, 'cyan': 36, 'white': 37, 'bold': 1,
             'italic': 3, 'underline': 4, 'inverse': 7,
             'black_background': 40, 'red_background': 41,
             'green_background': 42, 'yellow_background': 43,
@@ -435,16 +437,17 @@ def uisetup(ui):
 def extsetup(ui):
     commands.globalopts.append(
         ('', 'color', 'auto',
          # i18n: 'always', 'auto', and 'never' are keywords and should
          # not be translated
          _("when to colorize (boolean, always, auto, or never)"),
          _('TYPE')))
 
+ at command('debugcolor', [], 'hg debugcolor')
 def debugcolor(ui, repo, **opts):
     global _styles
     _styles = {}
     for effect in _effects.keys():
         _styles[effect] = effect
     ui.write(('color mode: %s\n') % ui._colormode)
     ui.write(_('available colors:\n'))
     for label, colors in _styles.items():
@@ -574,13 +577,8 @@ else:
                     if sattr:
                         attr = mapcolor(int(sattr), attr)
                 _kernel32.SetConsoleTextAttribute(stdout, attr)
                 orig(m.group(2), **opts)
                 m = re.match(ansire, m.group(3))
         finally:
             # Explicitly reset original attributes
             _kernel32.SetConsoleTextAttribute(stdout, origattr)
-
-cmdtable = {
-    'debugcolor':
-        (debugcolor, [], ('hg debugcolor'))
-}


More information about the Mercurial-devel mailing list