comparison hgext/progress.py @ 21859:be4270d27a7e

progress: use 'encoding.trim' to trim output line correctly Before this patch, 'progress' extension trims output line by directly slicing byte sequence, but it may split at intermediate multi-byte sequence. This patch uses 'encoding.trim' to trim output line correctly, even if it contains multi-byte characters. "rm -f loop.pyc" before changing "loop.py" in "test-progress.t" ensures that re-compilation of "loop.py", even if "loop.py" and "loop.pyc" have same timestamp in seconds.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sun, 06 Jul 2014 02:56:41 +0900
parents 4694ccd5d994
children e382cf9ec30b
comparison
equal deleted inserted replaced
21858:50fd3a36d166 21859:be4270d27a7e
38 import sys 38 import sys
39 import time 39 import time
40 40
41 from mercurial.i18n import _ 41 from mercurial.i18n import _
42 testedwith = 'internal' 42 testedwith = 'internal'
43
44 from mercurial import encoding
43 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
47 def shouldprint(ui): 49 def shouldprint(ui):
178 ' ' * int(abs(amt))) 180 ' ' * int(abs(amt)))
179 prog = ''.join(('[', bar , ']')) 181 prog = ''.join(('[', bar , ']'))
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
187 def clear(self): 189 def clear(self):
188 if not shouldprint(self.ui): 190 if not shouldprint(self.ui):