[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mercurial-devel
Subject:    [PATCH 2 of 2] color: add template label function
From:       Sean Farley <sean.michael.farley () gmail ! com>
Date:       2012-12-29 1:30:22
Message-ID: 5739e1cd5ce260376a6c.1356744622 () laptop ! local
[Download RAW message or body]

# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1356744310 21600
# Node ID 5739e1cd5ce260376a6cc55d0a7a0af75dfc2b84
# Parent  f80de1a51abf6299401672ce29ae38b1c192e3ec
color: add template label function

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,32 @@
         if effects:
             return '\n'.join([render_effects(s, effects)
                               for s in msg.split('\n')])
         return msg
 
+def templatelabel(context, mapping, args):
+    if len(args) != 2:
+        # i18n: "label" is a keyword
+        raise error.ParseError(_("label expects two arguments"))
+
+    thing = templater.stringify(args[1][0](context, mapping, args[1][1]))
+    thing = templater.runtemplate(context, mapping,
+                                  templater.compiletemplate(thing, context))
+
+    # apparently, repo could be a string that is the favicon?
+    repo = mapping.get('repo', '')
+    if isinstance(repo, str):
+        return thing
+
+    label = templater.stringify(args[0][0](context, mapping, args[0][1]))
+    label = templater.runtemplate(context, mapping,
+                                  templater.compiletemplate(label, context))
+
+    thing = templater.stringify(thing)
+    label = templater.stringify(label)
+
+    return repo.ui.label(thing, label)
 
 def uisetup(ui):
     global _terminfo_params
     if ui.plain():
         return
@@ -368,10 +391,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
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@selenic.com
http://selenic.com/mailman/listinfo/mercurial-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic