Mercurial > hg
changeset 7695:deec6628e62b
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.
author | Shun-ichi GOTO <shunichi.goto@gmail.com> |
---|---|
date | Wed, 21 Jan 2009 20:29:47 +0900 |
parents | 2ceeb1423544 |
children | 0895f95451e7 |
files | mercurial/commands.py mercurial/util.py |
diffstat | 2 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Thu Jan 22 10:48:37 2009 -0700 +++ b/mercurial/commands.py Wed Jan 21 20:29:47 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) @@ -2833,7 +2833,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"
--- a/mercurial/util.py Thu Jan 22 10:48:37 2009 -0700 +++ b/mercurial/util.py Wed Jan 21 20:29:47 2009 +0900 @@ -15,7 +15,7 @@ from i18n import _ import cStringIO, errno, getpass, re, shutil, sys, tempfile, traceback, error import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil -import imp +import imp, unicodedata # Python compatibility @@ -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: + if hasattr(unicodedata, 'east_asian_width'): + _colwidth = lambda s: sum([unicodedata.east_asian_width(c) in 'WF' + and 2 or 1 for c in s]) + else: + _colwidth = len + return _colwidth(s.decode(_encoding, "replace")) def version(): """Return version information if available."""