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

login
register
mail settings
Submitter Sean Farley
Date Dec. 24, 2012, 7:03 a.m.
Message ID <414aafdbce3cffe24b69.1356332592@laptop.local>
Download mbox | patch
Permalink /patch/293/
State Superseded
Headers show

Comments

Sean Farley - Dec. 24, 2012, 7:03 a.m.
# 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.

Patch

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():