Patchwork [2,of,3] color: enable debug option to show labels

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Sept. 3, 2014, 1:39 p.m.
Message ID <cfa2b9f3d8b7e58be542.1409751547@Iris>
Download mbox | patch
Permalink /patch/5688/
State Accepted
Headers show

Comments

Jordi Gutiérrez Hermoso - Sept. 3, 2014, 1:39 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1408916427 14400
#      Sun Aug 24 17:40:27 2014 -0400
# Node ID cfa2b9f3d8b7e58be5422a2c5e3ee79393955303
# Parent  c1b3584876e7a2e3001ce1324adde0fb94d23804
color: enable debug option to show labels

This is a debug option for showing labels. This can be helpful for
knowing which labels are available for colouring or to see the output
when defining your own templates. A couple of tests are included.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -27,6 +27,13 @@  that case, effects given to the last lab
 effects. This includes the special "none" effect, which nullifies
 other effects.
 
+Labels are normally invisible. In order to see these labels and their
+position in the text, use the global --color=debug option. In case of
+multiple labels for the same text, the labels will be enclosed by
+square brackets, e.g.
+
+  [log.changeset changeset.secret](changeset:   22611:6f0a53c8f587)
+
 The following are the default effects for some default labels. Default
 effects may be overridden from your configuration file::
 
@@ -178,6 +185,9 @@  def _terminfosetup(ui, mode):
 def _modesetup(ui, coloropt):
     global _terminfo_params
 
+    if coloropt == 'debug':
+        return 'debug'
+
     auto = (coloropt == 'auto')
     always = not auto and util.parsebool(coloropt)
     if not always and not auto:
@@ -389,10 +399,24 @@  class colorui(uimod.ui):
             return super(colorui, self).write_err(
                 *[self.label(str(a), label) for a in args], **opts)
 
+    def showlabel(self, msg, label):
+        if ' ' in label:
+            label = '[' + label + ']'
+        if label:
+            if msg and msg[-1] == '\n':
+                return "%s(%s)\n" % (label, msg[:-1])
+            else:
+                return "%s(%s)" % (label, msg)
+        else:
+            return msg
+
     def label(self, msg, label):
         if self._colormode is None:
             return super(colorui, self).label(msg, label)
 
+        if self._colormode == 'debug':
+            return self.showlabel(msg, label)
+
         effects = []
         for l in label.split():
             s = _styles.get(l, '')
@@ -438,7 +462,7 @@  def uisetup(ui):
     def colorcmd(orig, ui_, opts, cmd, cmdfunc):
         mode = _modesetup(ui_, opts['color'])
         colorui._colormode = mode
-        if mode:
+        if mode and mode != 'debug':
             extstyles()
             configstyles(ui_)
         return orig(ui_, opts, cmd, cmdfunc)
@@ -448,9 +472,9 @@  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)"),
+         # i18n: 'always', 'auto', 'never', and 'debug' are keywords
+         # and should not be translated
+         _("when to colorize (boolean, always, auto, never, or debug)"),
          _('TYPE')))
 
 @command('debugcolor', [], 'hg debugcolor')
diff --git a/tests/test-status-color.t b/tests/test-status-color.t
--- a/tests/test-status-color.t
+++ b/tests/test-status-color.t
@@ -20,6 +20,14 @@  hg status in repo root:
   \x1b[0;35;1;4m? \x1b[0m\x1b[0;35;1;4mb/in_b\x1b[0m (esc)
   \x1b[0;35;1;4m? \x1b[0m\x1b[0;35;1;4min_root\x1b[0m (esc)
 
+  $ hg status --color=debug
+  status.unknown(? )status.unknown(a/1/in_a_1)
+  status.unknown(? )status.unknown(a/in_a)
+  status.unknown(? )status.unknown(b/1/in_b_1)
+  status.unknown(? )status.unknown(b/2/in_b_2)
+  status.unknown(? )status.unknown(b/in_b)
+  status.unknown(? )status.unknown(in_root)
+
 hg status . in repo root:
 
   $ hg status --color=always .
@@ -137,6 +145,13 @@  Make sure ui.formatted=False works
   adding deleted
   adding modified
   adding removed
+  $ hg log --color=debug
+  [log.changeset changeset.draft](changeset:   0:389aef86a55e)
+  log.tag(tag:         tip)
+  log.user(user:        test)
+  log.date(date:        Thu Jan 01 00:00:00 1970 +0000)
+  log.summary(summary:     initial checkin)
+  
   $ touch modified added unknown ignored
   $ hg add added
   $ hg remove removed