Patchwork [5,of,5] color: add the ability to display configured style to 'debugcolor'

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 3, 2016, 3:56 p.m.
Message ID <cfef7fd6c10c67db9820.1478188596@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/17320/
State Accepted
Headers show

Comments

Pierre-Yves David - Nov. 3, 2016, 3:56 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1478182622 -3600
#      Thu Nov 03 15:17:02 2016 +0100
# Node ID cfef7fd6c10c67db982062c4761cdaf11eeaeec2
# Parent  ca827619fe6580c6e9220b0e98c6d9dfc51f6b4f
# EXP-Topic debugcolor
color: add the ability to display configured style to 'debugcolor'

The 'hg debugcolor' command gains a '--style' flag to display all the configured
labels and their styles. This have many benefits:

 * discovering documented label,
 * checking consistency between label's style,
 * showing the actual style of a label.
Yuya Nishihara - Nov. 4, 2016, 4:17 a.m.
On Thu, 03 Nov 2016 16:56:36 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1478182622 -3600
> #      Thu Nov 03 15:17:02 2016 +0100
> # Node ID cfef7fd6c10c67db982062c4761cdaf11eeaeec2
> # Parent  ca827619fe6580c6e9220b0e98c6d9dfc51f6b4f
> # EXP-Topic debugcolor
> color: add the ability to display configured style to 'debugcolor'

Nice. Queued the series, thanks.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -536,11 +536,16 @@  def extsetup(ui):
          _("when to colorize (boolean, always, auto, never, or debug)"),
          _('TYPE')))
 
-@command('debugcolor', [], 'hg debugcolor')
+@command('debugcolor',
+        [('', 'style', None, _('show all configured styles'))],
+        'hg debugcolor')
 def debugcolor(ui, repo, **opts):
-    """show available colors and effects"""
+    """show available color, effects or style"""
     ui.write(('color mode: %s\n') % ui._colormode)
-    return _debugdisplaycolor(ui)
+    if opts.get('style'):
+        return _debugdisplaystyle(ui)
+    else:
+        return _debugdisplaycolor(ui)
 
 def _debugdisplaycolor(ui):
     global _styles
@@ -564,6 +569,18 @@  def _debugdisplaycolor(ui):
     finally:
         _styles = oldstyle
 
+def _debugdisplaystyle(ui):
+    ui.write(_('available style:\n'))
+    width = max(len(s) for s in _styles)
+    for label, effects in sorted(_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')
+
 if os.name != 'nt':
     w32effects = None
 else: