##// END OF EJS Templates
template: add pad function for padding output...
Durham Goode -
r20370:aa51392d default
parent child Browse files
Show More
@@ -245,6 +245,31 b' def fill(context, mapping, args):'
245
245
246 return templatefilters.fill(text, width, initindent, hangindent)
246 return templatefilters.fill(text, width, initindent, hangindent)
247
247
248 def pad(context, mapping, args):
249 """usage: pad(text, width, fillchar=' ', right=False)
250 """
251 if not (2 <= len(args) <= 4):
252 raise error.ParseError(_("pad() expects two to four arguments"))
253
254 width = int(args[1][1])
255
256 text = stringify(args[0][0](context, mapping, args[0][1]))
257 if args[0][0] == runstring:
258 text = stringify(runtemplate(context, mapping,
259 compiletemplate(text, context)))
260
261 right = False
262 fillchar = ' '
263 if len(args) > 2:
264 fillchar = stringify(args[2][0](context, mapping, args[2][1]))
265 if len(args) > 3:
266 right = util.parsebool(args[3][1])
267
268 if right:
269 return text.rjust(width, fillchar)
270 else:
271 return text.ljust(width, fillchar)
272
248 def get(context, mapping, args):
273 def get(context, mapping, args):
249 if len(args) != 2:
274 if len(args) != 2:
250 # i18n: "get" is a keyword
275 # i18n: "get" is a keyword
@@ -407,6 +432,7 b' funcs = {'
407 "ifeq": ifeq,
432 "ifeq": ifeq,
408 "join": join,
433 "join": join,
409 "label": label,
434 "label": label,
435 "pad": pad,
410 "rstdoc": rstdoc,
436 "rstdoc": rstdoc,
411 "shortest": shortest,
437 "shortest": shortest,
412 "strip": strip,
438 "strip": strip,
@@ -1637,3 +1637,17 b' Test shortest(node) function:'
1637 $ hg log --template '{shortest(node, 10)}\n'
1637 $ hg log --template '{shortest(node, 10)}\n'
1638 d97c383ae3
1638 d97c383ae3
1639 f7769ec2ab
1639 f7769ec2ab
1640
1641 Test pad function
1642
1643 $ hg log --template '{pad(rev, 20)} {author|user}\n'
1644 1 test
1645 0 test
1646
1647 $ hg log --template '{pad(rev, 20, " ", True)} {author|user}\n'
1648 1 test
1649 0 test
1650
1651 $ hg log --template '{pad(rev, 20, "-", False)} {author|user}\n'
1652 1------------------- test
1653 0------------------- test
General Comments 0
You need to be logged in to leave comments. Login now