##// END OF EJS Templates
progress: use 'encoding.trim' to trim output line correctly...
FUJIWARA Katsunori -
r21859:be4270d2 default
parent child Browse files
Show More
@@ -41,6 +41,8 b' import time'
41 from mercurial.i18n import _
41 from mercurial.i18n import _
42 testedwith = 'internal'
42 testedwith = 'internal'
43
43
44 from mercurial import encoding
45
44 def spacejoin(*args):
46 def spacejoin(*args):
45 return ' '.join(s for s in args if s)
47 return ' '.join(s for s in args if s)
46
48
@@ -180,7 +182,7 b' class progbar(object):'
180 out = spacejoin(head, prog, tail)
182 out = spacejoin(head, prog, tail)
181 else:
183 else:
182 out = spacejoin(head, tail)
184 out = spacejoin(head, tail)
183 sys.stderr.write('\r' + out[:termwidth])
185 sys.stderr.write('\r' + encoding.trim(out, termwidth))
184 self.lasttopic = topic
186 self.lasttopic = topic
185 sys.stderr.flush()
187 sys.stderr.flush()
186
188
@@ -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('loop', i, 'loop.%d' % i, 'loopnum', total)
36 > ui.progress(topiclabel, i, 'loop.%d' % 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:
@@ -45,7 +45,9 b''
45 > 'nested', j, 'nested.%d' % j, 'nestnum', nested_steps)
45 > 'nested', j, 'nested.%d' % j, 'nestnum', nested_steps)
46 > ui.progress(
46 > ui.progress(
47 > 'nested', None, 'nested.done', 'nestnum', nested_steps)
47 > 'nested', None, 'nested.done', 'nestnum', nested_steps)
48 > ui.progress('loop', None, 'loop.done', 'loopnum', total)
48 > ui.progress(topiclabel, None, 'loop.done', 'loopnum', total)
49 >
50 > topiclabel = 'loop'
49 >
51 >
50 > EOF
52 > EOF
51
53
@@ -238,3 +240,38 b' Time estimates should not fail when ther'
238 loop [ <=> ] 2\r (no-eol) (esc)
240 loop [ <=> ] 2\r (no-eol) (esc)
239 loop [ <=> ] 3\r (no-eol) (esc)
241 loop [ <=> ] 3\r (no-eol) (esc)
240 \r (no-eol) (esc)
242 \r (no-eol) (esc)
243
244 test line trimming by '[progress] width', when progress topic contains
245 multi-byte characters, of which length of byte sequence and columns in
246 display are different from each other.
247
248 $ cp $HGRCPATH.orig $HGRCPATH
249 $ cat >> $HGRCPATH <<EOF
250 > [extensions]
251 > progress=
252 > loop=`pwd`/loop.py
253 > [progress]
254 > assume-tty = 1
255 > delay = 0
256 > refresh = 0
257 > EOF
258
259 $ rm -f loop.pyc
260 $ cat >> loop.py <<EOF
261 > # use non-ascii characters as topic label of progress
262 > # 2 x 4 = 8 columns, but 3 x 4 = 12 bytes
263 > topiclabel = u'\u3042\u3044\u3046\u3048'.encode('utf-8')
264 > EOF
265
266 $ cat >> $HGRCPATH <<EOF
267 > [progress]
268 > format = topic number
269 > width= 12
270 > EOF
271
272 $ hg --encoding utf-8 -y loop --total 3 3
273 \r (no-eol) (esc)
274 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 0/3\r (no-eol) (esc)
275 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 1/3\r (no-eol) (esc)
276 \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88 2/3\r (no-eol) (esc)
277 \r (no-eol) (esc)
General Comments 0
You need to be logged in to leave comments. Login now