mercurial/encoding.py
branchstable
changeset 12866 eddc20306ab6
parent 12770 614f0d8724ab
child 13046 7cc4263e07a9
equal deleted inserted replaced
12865:4c50552fc9bc 12866:eddc20306ab6
    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