[PATCH 5 of 6 RFC] color: extract symbol from template label args

Sean Farley sean.michael.farley at gmail.com
Mon Dec 24 01:03:12 CST 2012


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1356329650 21600
# Node ID 414aafdbce3cffe24b69d652055f443d9cad9f68
# Parent  ff411dd59f4ef22383b647ae2e0c98da1310bba4
color: extract symbol from template label args

This could be abstracted to a function call later, if the need arises.

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -380,10 +380,16 @@
 def templatelabel(context, mapping, args):
     if not (1 <= len(args) <= 2):
         # i18n: "label" is a keyword
         raise error.ParseError(_("label expects one or two arguments"))
 
+    def extractsymbol(exp):
+        for e in exp:
+            if e == str(templater.runsymbol):
+                return exp.next()
+        return ''
+
     thing = args[0][0](context, mapping, args[0][1])
     label = ''
 
     # repo could be a string, apparently, that is the favicon?
     repo = mapping.get('repo', '')
@@ -395,10 +401,16 @@
 
     if thing is None:
         thing = ''
     thing = templater.stringify(thing)
 
+    sym = extractsymbol(templater._flatten(args[0]))
+    default_label = _labels.get(sym, '')
+
+    if default_label:
+        label = default_label + ' ' + label
+
     return repo.ui.label(thing, label)
 
 def uisetup(ui):
     global _terminfo_params
     if ui.plain():


More information about the Mercurial-devel mailing list