##// END OF EJS Templates
progress: use 'encoding.trim' to trim items in output line correctly...
FUJIWARA Katsunori -
r21862:ba7f75e7 default
parent child Browse files
Show More
@@ -139,9 +139,9 b' class progbar(object):'
139 else:
139 else:
140 wid = 20
140 wid = 20
141 if slice == 'end':
141 if slice == 'end':
142 add = item[-wid:]
142 add = encoding.trim(item, wid, leftside=True)
143 else:
143 else:
144 add = item[:wid]
144 add = encoding.trim(item, wid)
145 add += (wid - len(add)) * ' '
145 add += (wid - len(add)) * ' '
146 elif indicator == 'bar':
146 elif indicator == 'bar':
147 add = ''
147 add = ''
@@ -33,7 +33,7 b''
33 > loops = abs(loops)
33 > loops = abs(loops)
34 >
34 >
35 > for i in range(loops):
35 > for i in range(loops):
36 > ui.progress(topiclabel, i, 'loop.%d' % i, 'loopnum', total)
36 > ui.progress(topiclabel, i, getloopitem(i), 'loopnum', total)
37 > if opts.get('parallel'):
37 > if opts.get('parallel'):
38 > ui.progress('other', i, 'other.%d' % i, 'othernum', total)
38 > ui.progress('other', i, 'other.%d' % i, 'othernum', total)
39 > if nested:
39 > if nested:
@@ -48,6 +48,8 b''
48 > ui.progress(topiclabel, None, 'loop.done', 'loopnum', total)
48 > ui.progress(topiclabel, None, 'loop.done', 'loopnum', total)
49 >
49 >
50 > topiclabel = 'loop'
50 > topiclabel = 'loop'
51 > def getloopitem(i):
52 > return 'loop.%d' % i
51 >
53 >
52 > EOF
54 > EOF
53
55
@@ -293,3 +295,42 b' are different from each other.'
293 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 [==> ]\r (no-eol) (esc)
295 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 [==> ]\r (no-eol) (esc)
294 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 [=====> ]\r (no-eol) (esc)
296 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 [=====> ]\r (no-eol) (esc)
295 \r (no-eol) (esc)
297 \r (no-eol) (esc)
298
299 test triming progress items, when they contain multi-byte characters,
300 of which length of byte sequence and columns in display are different
301 from each other.
302
303 $ rm -f loop.pyc
304 $ cat >> loop.py <<EOF
305 > # use non-ascii characters as loop items of progress
306 > loopitems = [
307 > u'\u3042\u3044\u3046'.encode('utf-8'), # 2 x 3 = 6 columns
308 > u'\u3042\u3044\u3046\u3048'.encode('utf-8'), # 2 x 4 = 8 columns
309 > ]
310 > def getloopitem(i):
311 > return loopitems[i % len(loopitems)]
312 > EOF
313
314 $ cat >> $HGRCPATH <<EOF
315 > [progress]
316 > # trim at tail side
317 > format = item+6
318 > EOF
319
320 $ hg --encoding utf-8 -y loop --total 2 2
321 \r (no-eol) (esc)
322 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
323 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
324 \r (no-eol) (esc)
325
326 $ cat >> $HGRCPATH <<EOF
327 > [progress]
328 > # trim at left side
329 > format = item-6
330 > EOF
331
332 $ hg --encoding utf-8 -y loop --total 2 2
333 \r (no-eol) (esc)
334 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
335 \xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\r (no-eol) (esc)
336 \r (no-eol) (esc)
General Comments 0
You need to be logged in to leave comments. Login now