##// END OF EJS Templates
templater: make label() take unknown symbol as color literal...
Yuya Nishihara -
r28373:9a9dd71e default
parent child Browse files
Show More
@@ -485,10 +485,6 b' def templatelabel(context, mapping, args'
485 # i18n: "label" is a keyword
485 # i18n: "label" is a keyword
486 raise error.ParseError(_("label expects two arguments"))
486 raise error.ParseError(_("label expects two arguments"))
487
487
488 # add known effects to the mapping so symbols like 'red', 'bold',
489 # etc. don't need to be quoted
490 mapping.update(dict([(k, k) for k in _effects]))
491
492 thing = templater.evalstring(context, mapping, args[1])
488 thing = templater.evalstring(context, mapping, args[1])
493
489
494 # apparently, repo could be a string that is the favicon?
490 # apparently, repo could be a string that is the favicon?
@@ -496,7 +492,9 b' def templatelabel(context, mapping, args'
496 if isinstance(repo, str):
492 if isinstance(repo, str):
497 return thing
493 return thing
498
494
499 label = templater.evalstring(context, mapping, args[0])
495 # preserve unknown symbol as literal so effects like 'red', 'bold',
496 # etc. don't need to be quoted
497 label = templater.evalstringliteral(context, mapping, args[0])
500
498
501 return repo.ui.label(thing, label)
499 return repo.ui.label(thing, label)
502
500
@@ -231,6 +231,16 b' def evalstring(context, mapping, arg):'
231 func, data = arg
231 func, data = arg
232 return stringify(func(context, mapping, data))
232 return stringify(func(context, mapping, data))
233
233
234 def evalstringliteral(context, mapping, arg):
235 """Evaluate given argument as string template, but returns symbol name
236 if it is unknown"""
237 func, data = arg
238 if func is runsymbol:
239 thing = func(context, mapping, data, default=data)
240 else:
241 thing = func(context, mapping, data)
242 return stringify(thing)
243
234 def runinteger(context, mapping, data):
244 def runinteger(context, mapping, data):
235 return int(data)
245 return int(data)
236
246
@@ -245,7 +255,7 b' def _recursivesymbolblocker(key):'
245 def _runrecursivesymbol(context, mapping, key):
255 def _runrecursivesymbol(context, mapping, key):
246 raise error.Abort(_("recursive reference '%s' in template") % key)
256 raise error.Abort(_("recursive reference '%s' in template") % key)
247
257
248 def runsymbol(context, mapping, key):
258 def runsymbol(context, mapping, key, default=''):
249 v = mapping.get(key)
259 v = mapping.get(key)
250 if v is None:
260 if v is None:
251 v = context._defaults.get(key)
261 v = context._defaults.get(key)
@@ -257,7 +267,7 b' def runsymbol(context, mapping, key):'
257 try:
267 try:
258 v = context.process(key, safemapping)
268 v = context.process(key, safemapping)
259 except TemplateNotFound:
269 except TemplateNotFound:
260 v = ''
270 v = default
261 if callable(v):
271 if callable(v):
262 return v(**mapping)
272 return v(**mapping)
263 return v
273 return v
@@ -3178,6 +3178,11 b' Test recursive evaluation:'
3178 $ hg log --color=always -l 1 --template '{label("text.{rev}", "text\n")}'
3178 $ hg log --color=always -l 1 --template '{label("text.{rev}", "text\n")}'
3179 \x1b[0;32mtext\x1b[0m (esc)
3179 \x1b[0;32mtext\x1b[0m (esc)
3180
3180
3181 color effect can be specified without quoting:
3182
3183 $ hg log --color=always -l 1 --template '{label(red, "text\n")}'
3184 \x1b[0;31mtext\x1b[0m (esc)
3185
3181 Test branches inside if statement:
3186 Test branches inside if statement:
3182
3187
3183 $ hg log -r 0 --template '{if(branches, "yes", "no")}\n'
3188 $ hg log -r 0 --template '{if(branches, "yes", "no")}\n'
General Comments 0
You need to be logged in to leave comments. Login now