[PATCH] Also find correct column width of wide characters
Shun-ichi Goto
shunichi.goto at gmail.com
Tue Jan 20 04:47:01 CST 2009
# HG changeset patch
# User Shun-ichi GOTO <shunichi.goto at gmail.com>
# Date 1232448313 -32400
# Node ID 48dae234cdb18438049fea110d37eb97c61e17ab
# Parent 08886617f7a36b3e7b6b2b9b4f418a6bd8047828
Also find correct column width of wide characters.
Use unicodedata.east_asian_width() to determine wide/full width
characters if available. Otherwise, return character count as before.
diff -r 08886617f7a3 -r 48dae234cdb1 mercurial/commands.py
--- a/mercurial/commands.py Tue Jan 20 19:24:00 2009 +0900
+++ b/mercurial/commands.py Tue Jan 20 19:45:13 2009 +0900
@@ -448,7 +448,7 @@
notice = ' (closed)'
else:
notice = ' (inactive)'
- rev = str(node).rjust(31 - util.locallen(tag))
+ rev = str(node).rjust(31 - util.colwidth(tag))
data = tag, rev, hexfunc(hn), notice
ui.write("%s %s:%s%s\n" % data)
@@ -2870,7 +2870,7 @@
except error.LookupError:
r = " ?:%s" % hn
else:
- spaces = " " * (30 - util.locallen(t))
+ spaces = " " * (30 - util.colwidth(t))
if ui.verbose:
if repo.tagtype(t) == 'local':
tagtype = " local"
diff -r 08886617f7a3 -r 48dae234cdb1 mercurial/util.py
--- a/mercurial/util.py Tue Jan 20 19:24:00 2009 +0900
+++ b/mercurial/util.py Tue Jan 20 19:45:13 2009 +0900
@@ -138,9 +138,17 @@
except LookupError, k:
raise Abort(_("%s, please check your locale settings") % k)
-def locallen(s):
- """Find the length in characters of a local string"""
- return len(s.decode(_encoding, "replace"))
+_colwidth = None
+def colwidth(s):
+ """Find the column width of string to display."""
+ global _colwidth
+ if _colwidth is None:
+ try:
+ from unicodedata import east_asian_width as eaw
+ _colwidth = lambda s: sum([eaw(c) in 'WF' and 2 or 1 for c in s])
+ except:
+ _colwidth = len
+ return _colwidth(s.decode(_encoding, "replace"))
def version():
"""Return version information if available."""
More information about the Mercurial-devel
mailing list