##// END OF EJS Templates
templatefuncs: add truncate parameter to pad...
Mark Thomas -
r40225:9458dbfa default
parent child Browse files
Show More
@@ -216,8 +216,9 b' def mailmap(context, mapping, args):'
216 216
217 217 return stringutil.mapname(cache['mailmap'], author)
218 218
219 @templatefunc('pad(text, width[, fillchar=\' \'[, left=False]])',
220 argspec='text width fillchar left')
219 @templatefunc(
220 'pad(text, width[, fillchar=\' \'[, left=False[, truncate=False]]])',
221 argspec='text width fillchar left truncate')
221 222 def pad(context, mapping, args):
222 223 """Pad text with a
223 224 fill character."""
@@ -231,6 +232,7 b' def pad(context, mapping, args):'
231 232
232 233 text = evalstring(context, mapping, args['text'])
233 234
235 truncate = False
234 236 left = False
235 237 fillchar = ' '
236 238 if 'fillchar' in args:
@@ -240,8 +242,12 b' def pad(context, mapping, args):'
240 242 raise error.ParseError(_("pad() expects a single fill character"))
241 243 if 'left' in args:
242 244 left = evalboolean(context, mapping, args['left'])
245 if 'truncate' in args:
246 truncate = evalboolean(context, mapping, args['truncate'])
243 247
244 248 fillwidth = width - encoding.colwidth(color.stripeffects(text))
249 if fillwidth < 0 and truncate:
250 return encoding.trim(color.stripeffects(text), width, leftside=left)
245 251 if fillwidth <= 0:
246 252 return text
247 253 if left:
@@ -696,6 +696,12 b' pad() should interact well with color co'
696 696 > '{pad(label(red, "red"), 5, label(cyan, "-"))}\n'
697 697 \x1b[0;31mred\x1b[0m\x1b[0;36m-\x1b[0m\x1b[0;36m-\x1b[0m (esc)
698 698
699 pad() with truncate has to strip color codes, though
700
701 $ hg debugtemplate --color=always \
702 > '{pad(label(red, "scarlet"), 5, truncate=true)}\n'
703 scarl
704
699 705 label should be no-op if color is disabled:
700 706
701 707 $ hg log --color=never -l 1 --template '{label(red, "text\n")}'
@@ -928,6 +934,15 b' Test pad function'
928 934 1------------------- {node|short}
929 935 0------------------- test
930 936
937 $ hg log --template '{pad(author, 5, "-", False, True)}\n'
938 test-
939 {node
940 test-
941 $ hg log --template '{pad(author, 5, "-", True, True)}\n'
942 -test
943 hort}
944 -test
945
931 946 Test template string in pad function
932 947
933 948 $ hg log -r 0 -T '{pad("\{{rev}}", 10)} {author|user}\n'
General Comments 0
You need to be logged in to leave comments. Login now