Patchwork [4,of,5] color: sort output of 'debugcolor'

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 3, 2016, 3:56 p.m.
Message ID <ca827619fe6580c6e922.1478188595@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/17319/
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 1478182547 -3600
#      Thu Nov 03 15:15:47 2016 +0100
# Node ID ca827619fe6580c6e9220b0e98c6d9dfc51f6b4f
# Parent  a426f9f5c76af2ae94500d9a4c845a5d12b27bbc
# EXP-Topic debugcolor
color: sort output of 'debugcolor'

The previous ordering were provided by the set. The new output is more stable
and rational. In addition we have some logic to keep the '_background' version
together to help readability.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -556,7 +556,10 @@  def _debugdisplaycolor(ui):
                 elif k.startswith('terminfo.'):
                     _styles[k] = k[9:]
         ui.write(_('available colors:\n'))
-        for colorname, label in _styles.items():
+        # sort label with a '_' after the other to group '_background' entry.
+        items = sorted(_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:
         _styles = oldstyle