comparison tests/test-progress.t @ 21863:f9c91c638378

progress: use 'encoding.colwidth' to get column width of items correctly Before this patch, 'progress' extension applies 'len' on byte sequence to get column width of it, but it causes incorrect result, when length of byte sequence and columns in display are different from each other in multi-byte characters. This patch uses 'encoding.colwidth' to get column width of items in output line correctly, even if it contains multi-byte characters.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sun, 06 Jul 2014 02:56:41 +0900
parents ba7f75e7f4e5
children e53f6b72a0e4
comparison
equal deleted inserted replaced
21862:ba7f75e7f4e5 21863:f9c91c638378
302 302
303 $ rm -f loop.pyc 303 $ rm -f loop.pyc
304 $ cat >> loop.py <<EOF 304 $ cat >> loop.py <<EOF
305 > # use non-ascii characters as loop items of progress 305 > # use non-ascii characters as loop items of progress
306 > loopitems = [ 306 > loopitems = [
307 > u'\u3042\u3044'.encode('utf-8'), # 2 x 2 = 4 columns
307 > u'\u3042\u3044\u3046'.encode('utf-8'), # 2 x 3 = 6 columns 308 > 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 > u'\u3042\u3044\u3046\u3048'.encode('utf-8'), # 2 x 4 = 8 columns
309 > ] 310 > ]
310 > def getloopitem(i): 311 > def getloopitem(i):
311 > return loopitems[i % len(loopitems)] 312 > return loopitems[i % len(loopitems)]
315 > [progress] 316 > [progress]
316 > # trim at tail side 317 > # trim at tail side
317 > format = item+6 318 > format = item+6
318 > EOF 319 > EOF
319 320
320 $ hg --encoding utf-8 -y loop --total 2 2 321 $ hg --encoding utf-8 -y loop --total 3 3
321 \r (no-eol) (esc) 322 \r (no-eol) (esc)
323 \xe3\x81\x82\xe3\x81\x84 \r (no-eol) (esc)
322 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc) 324 \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) 325 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
324 \r (no-eol) (esc) 326 \r (no-eol) (esc)
325 327
326 $ cat >> $HGRCPATH <<EOF 328 $ cat >> $HGRCPATH <<EOF
327 > [progress] 329 > [progress]
328 > # trim at left side 330 > # trim at left side
329 > format = item-6 331 > format = item-6
330 > EOF 332 > EOF
331 333
332 $ hg --encoding utf-8 -y loop --total 2 2 334 $ hg --encoding utf-8 -y loop --total 3 3
333 \r (no-eol) (esc) 335 \r (no-eol) (esc)
336 \xe3\x81\x82\xe3\x81\x84 \r (no-eol) (esc)
334 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc) 337 \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) 338 \xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\r (no-eol) (esc)
336 \r (no-eol) (esc) 339 \r (no-eol) (esc)