Patchwork color: add effect to the template symbol table

login
register
mail settings
Submitter Sean Farley
Date April 14, 2014, 11:25 p.m.
Message ID <eeba1982fac05351bbfc.1397517959@laptop.local>
Download mbox | patch
Permalink /patch/4347/
State Accepted
Commit b775a2029e8d9a7494a1c274f0079988e915bed4
Headers show

Comments

Sean Farley - April 14, 2014, 11:25 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1397517686 18000
#      Mon Apr 14 18:21:26 2014 -0500
# Node ID eeba1982fac05351bbfc729ec3314eaa195eb59d
# Parent  76f68595ff8e5616a79dd79e962a97cc9ba58713
color: add effect to the template symbol table

Previously, words like 'red' had to be protected by quotes before passing to
the label template function. Now, we add color effects to the symbol table so
that commands like,

$ hg log -r . -T "{label(red, node|short)}\n"

can work without the need for quoting.
Durham Goode - April 15, 2014, 1:05 a.m.
On 4/14/14, 4:25 PM, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1397517686 18000
> #      Mon Apr 14 18:21:26 2014 -0500
> # Node ID eeba1982fac05351bbfc729ec3314eaa195eb59d
> # Parent  76f68595ff8e5616a79dd79e962a97cc9ba58713
> color: add effect to the template symbol table
>
> Previously, words like 'red' had to be protected by quotes before passing to
> the label template function. Now, we add color effects to the symbol table so
> that commands like,
>
> $ hg log -r . -T "{label(red, node|short)}\n"
>
> can work without the need for quoting.
>
> diff --git a/hgext/color.py b/hgext/color.py
> --- a/hgext/color.py
> +++ b/hgext/color.py
> @@ -393,10 +393,14 @@ class colorui(uimod.ui):
>   def templatelabel(context, mapping, args):
>       if len(args) != 2:
>           # i18n: "label" is a keyword
>           raise error.ParseError(_("label expects two arguments"))
>   
> +    # add known effects to the mapping so symbols like 'red', 'bold',
> +    # etc. don't need to be quoted
> +    mapping.update(dict([(k, k) for k in _effects]))
> +
>       thing = templater._evalifliteral(args[1], context, mapping)
>   
>       # apparently, repo could be a string that is the favicon?
>       repo = mapping.get('repo', '')
>       if isinstance(repo, str):
>
Sweet! Queued for default.

Patch

diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -393,10 +393,14 @@  class colorui(uimod.ui):
 def templatelabel(context, mapping, args):
     if len(args) != 2:
         # i18n: "label" is a keyword
         raise error.ParseError(_("label expects two arguments"))
 
+    # add known effects to the mapping so symbols like 'red', 'bold',
+    # etc. don't need to be quoted
+    mapping.update(dict([(k, k) for k in _effects]))
+
     thing = templater._evalifliteral(args[1], context, mapping)
 
     # apparently, repo could be a string that is the favicon?
     repo = mapping.get('repo', '')
     if isinstance(repo, str):