Patchwork [8,of,8,STABLE] progress: use 'encoding.colwidth' to get column width of items correctly

login
register
mail settings
Submitter Katsunori FUJIWARA
Date June 13, 2014, 4:22 p.m.
Message ID <a0033b01105cfc476f95.1402676556@feefifofum>
Download mbox | patch
Permalink /patch/4994/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - June 13, 2014, 4:22 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1402675901 -32400
#      Sat Jun 14 01:11:41 2014 +0900
# Branch stable
# Node ID a0033b01105cfc476f95244b3855651860d0a808
# Parent  8a3053db8c90be14bcd81624479633098233550f
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.

Patch

diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -142,7 +142,7 @@ 
                     add = encoding.trim(item, wid, headside=True)
                 else:
                     add = encoding.trim(item, wid)
-                add += (wid - len(add)) * ' '
+                add += (wid - encoding.colwidth(add)) * ' '
             elif indicator == 'bar':
                 add = ''
                 needprogress = True
diff --git a/tests/test-progress.t b/tests/test-progress.t
--- a/tests/test-progress.t
+++ b/tests/test-progress.t
@@ -301,6 +301,7 @@ 
   $ rm -f loop.pyc
   $ cat >> loop.py <<EOF
   > loopitems = [
+  >     u'\u3042\u3044'.encode('utf-8'), # 2 x 2 = 4 columns
   >     u'\u3042\u3044\u3046'.encode('utf-8'), # 2 x 3 = 6 columns
   >     u'\u3042\u3044\u3046\u3048'.encode('utf-8'), # 2 x 4 = 8 columns
   > ]
@@ -314,8 +315,9 @@ 
   > format = item+6
   > EOF
 
-  $ hg --encoding utf-8 -y loop --total 2 2
-  \r (no-eol) (esc)
+  $ hg --encoding utf-8 -y loop --total 3 3
+  \r (no-eol) (esc)
+  \xe3\x81\x82\xe3\x81\x84  \r (no-eol) (esc)
   \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
   \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
                        \r (no-eol) (esc)
@@ -326,8 +328,9 @@ 
   > format = item-6
   > EOF
 
-  $ hg --encoding utf-8 -y loop --total 2 2
-  \r (no-eol) (esc)
+  $ hg --encoding utf-8 -y loop --total 3 3
+  \r (no-eol) (esc)
+  \xe3\x81\x82\xe3\x81\x84  \r (no-eol) (esc)
   \xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\r (no-eol) (esc)
   \xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\r (no-eol) (esc)
                        \r (no-eol) (esc)