diff --git a/hgext/progress.py b/hgext/progress.py --- a/hgext/progress.py +++ b/hgext/progress.py @@ -41,6 +41,8 @@ import time from mercurial.i18n import _ testedwith = 'internal' +from mercurial import encoding + def spacejoin(*args): return ' '.join(s for s in args if s) @@ -180,7 +182,7 @@ class progbar(object): out = spacejoin(head, prog, tail) else: out = spacejoin(head, tail) - sys.stderr.write('\r' + out[:termwidth]) + sys.stderr.write('\r' + encoding.trim(out, termwidth)) self.lasttopic = topic sys.stderr.flush() diff --git a/tests/test-progress.t b/tests/test-progress.t --- a/tests/test-progress.t +++ b/tests/test-progress.t @@ -33,7 +33,7 @@ > loops = abs(loops) > > for i in range(loops): - > ui.progress('loop', i, 'loop.%d' % i, 'loopnum', total) + > ui.progress(topiclabel, i, 'loop.%d' % i, 'loopnum', total) > if opts.get('parallel'): > ui.progress('other', i, 'other.%d' % i, 'othernum', total) > if nested: @@ -45,7 +45,9 @@ > 'nested', j, 'nested.%d' % j, 'nestnum', nested_steps) > ui.progress( > 'nested', None, 'nested.done', 'nestnum', nested_steps) - > ui.progress('loop', None, 'loop.done', 'loopnum', total) + > ui.progress(topiclabel, None, 'loop.done', 'loopnum', total) + > + > topiclabel = 'loop' > > EOF @@ -238,3 +240,38 @@ Time estimates should not fail when ther loop [ <=> ] 2\r (no-eol) (esc) loop [ <=> ] 3\r (no-eol) (esc) \r (no-eol) (esc) + +test line trimming by '[progress] width', when progress topic contains +multi-byte characters, of which length of byte sequence and columns in +display are different from each other. + + $ cp $HGRCPATH.orig $HGRCPATH + $ cat >> $HGRCPATH < [extensions] + > progress= + > loop=`pwd`/loop.py + > [progress] + > assume-tty = 1 + > delay = 0 + > refresh = 0 + > EOF + + $ rm -f loop.pyc + $ cat >> loop.py < # use non-ascii characters as topic label of progress + > # 2 x 4 = 8 columns, but 3 x 4 = 12 bytes + > topiclabel = u'\u3042\u3044\u3046\u3048'.encode('utf-8') + > EOF + + $ cat >> $HGRCPATH < [progress] + > format = topic number + > width= 12 + > EOF + + $ hg --encoding utf-8 -y loop --total 3 3 + \r (no-eol) (esc) + \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 0/3\r (no-eol) (esc) + \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 1/3\r (no-eol) (esc) + \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 2/3\r (no-eol) (esc) + \r (no-eol) (esc)