Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 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 | e62a456b8dc5 |
children | 0895f95451e7 |
comparison
equal
deleted
inserted
replaced
7694:2ceeb1423544 | 7695:deec6628e62b |
---|---|
13 """ | 13 """ |
14 | 14 |
15 from i18n import _ | 15 from i18n import _ |
16 import cStringIO, errno, getpass, re, shutil, sys, tempfile, traceback, error | 16 import cStringIO, errno, getpass, re, shutil, sys, tempfile, traceback, error |
17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil | 17 import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil |
18 import imp | 18 import imp, unicodedata |
19 | 19 |
20 # Python compatibility | 20 # Python compatibility |
21 | 21 |
22 try: | 22 try: |
23 set = set | 23 set = set |
136 sub = s[max(0, inst.start-10):inst.start+10] | 136 sub = s[max(0, inst.start-10):inst.start+10] |
137 raise Abort("decoding near '%s': %s!" % (sub, inst)) | 137 raise Abort("decoding near '%s': %s!" % (sub, inst)) |
138 except LookupError, k: | 138 except LookupError, k: |
139 raise Abort(_("%s, please check your locale settings") % k) | 139 raise Abort(_("%s, please check your locale settings") % k) |
140 | 140 |
141 def locallen(s): | 141 _colwidth = None |
142 """Find the length in characters of a local string""" | 142 def colwidth(s): |
143 return len(s.decode(_encoding, "replace")) | 143 """Find the column width of string to display.""" |
144 global _colwidth | |
145 if _colwidth is None: | |
146 if hasattr(unicodedata, 'east_asian_width'): | |
147 _colwidth = lambda s: sum([unicodedata.east_asian_width(c) in 'WF' | |
148 and 2 or 1 for c in s]) | |
149 else: | |
150 _colwidth = len | |
151 return _colwidth(s.decode(_encoding, "replace")) | |
144 | 152 |
145 def version(): | 153 def version(): |
146 """Return version information if available.""" | 154 """Return version information if available.""" |
147 try: | 155 try: |
148 import __version__ | 156 import __version__ |