85 sub = s[max(0, inst.start - 10):inst.start + 10] |
85 sub = s[max(0, inst.start - 10):inst.start + 10] |
86 raise error.Abort("decoding near '%s': %s!" % (sub, inst)) |
86 raise error.Abort("decoding near '%s': %s!" % (sub, inst)) |
87 except LookupError, k: |
87 except LookupError, k: |
88 raise error.Abort("%s, please check your locale settings" % k) |
88 raise error.Abort("%s, please check your locale settings" % k) |
89 |
89 |
|
90 # How to treat ambiguous-width characters. Set to 'wide' to treat as wide. |
|
91 ambiguous = os.environ.get("HGENCODINGAMBIGUOUS", "narrow") |
|
92 |
90 def colwidth(s): |
93 def colwidth(s): |
91 "Find the column width of a UTF-8 string for display" |
94 "Find the column width of a UTF-8 string for display" |
92 d = s.decode(encoding, 'replace') |
95 d = s.decode(encoding, 'replace') |
93 if hasattr(unicodedata, 'east_asian_width'): |
96 if hasattr(unicodedata, 'east_asian_width'): |
|
97 wide = "WF" |
|
98 if ambiguous == "wide": |
|
99 wide = "WFA" |
94 w = unicodedata.east_asian_width |
100 w = unicodedata.east_asian_width |
95 return sum([w(c) in 'WFA' and 2 or 1 for c in d]) |
101 return sum([w(c) in wide and 2 or 1 for c in d]) |
96 return len(d) |
102 return len(d) |
97 |
103 |