Patchwork [3,of,6,RFC] color: add template label function

login
register
mail settings
Submitter Sean Farley
Date Dec. 24, 2012, 7:03 a.m.
Message ID <7270e507a63ecf14622e.1356332590@laptop.local>
Download mbox | patch
Permalink /patch/292/
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 1356329556 21600
# Node ID 7270e507a63ecf14622e07d4f2809929acfca6f7
# Parent  75ef781d20973d036f003bba00a873bf1c5d5598
color: add template label function

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -101,10 +101,11 @@ 
 '''
 
 import os
 
 from mercurial import commands, dispatch, extensions, ui as uimod, util
+from mercurial import templater
 from mercurial.i18n import _
 
 testedwith = 'internal'
 
 # start and stop parameters for effects
@@ -352,10 +353,31 @@ 
         if effects:
             return '\n'.join([render_effects(s, effects)
                               for s in msg.split('\n')])
         return msg
 
+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"))
+
+    thing = args[0][0](context, mapping, args[0][1])
+    label = ''
+
+    # repo could be a string, apparently, that is the favicon?
+    repo = mapping.get('repo', '')
+    if isinstance(repo, str):
+        return thing
+
+    if len(args) > 1:
+        label = args[1][0](context, mapping, args[1][1])
+
+    if thing is None:
+        thing = ''
+    thing = templater.stringify(thing)
+
+    return repo.ui.label(thing, label)
 
 def uisetup(ui):
     global _terminfo_params
     if ui.plain():
         return
@@ -368,10 +390,11 @@ 
                 ui_.__class__ = colorui
             extstyles()
             configstyles(ui_)
         return orig(ui_, opts, cmd, cmdfunc)
     extensions.wrapfunction(dispatch, '_runcommand', colorcmd)
+    templater.funcs['label'] = templatelabel
 
 def extsetup(ui):
     commands.globalopts.append(
         ('', 'color', 'auto',
          # i18n: 'always', 'auto', and 'never' are keywords and should