Show More
@@ -245,6 +245,31 b' def fill(context, mapping, args):' | |||
|
245 | 245 | |
|
246 | 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 | 273 | def get(context, mapping, args): |
|
249 | 274 | if len(args) != 2: |
|
250 | 275 | # i18n: "get" is a keyword |
@@ -407,6 +432,7 b' funcs = {' | |||
|
407 | 432 | "ifeq": ifeq, |
|
408 | 433 | "join": join, |
|
409 | 434 | "label": label, |
|
435 | "pad": pad, | |
|
410 | 436 | "rstdoc": rstdoc, |
|
411 | 437 | "shortest": shortest, |
|
412 | 438 | "strip": strip, |
@@ -1637,3 +1637,17 b' Test shortest(node) function:' | |||
|
1637 | 1637 | $ hg log --template '{shortest(node, 10)}\n' |
|
1638 | 1638 | d97c383ae3 |
|
1639 | 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