equal
deleted
inserted
replaced
14 import unicodedata |
14 import unicodedata |
15 |
15 |
16 from typing import ( |
16 from typing import ( |
17 Any, |
17 Any, |
18 Callable, |
18 Callable, |
19 Text, |
|
20 TypeVar, |
19 TypeVar, |
21 ) |
20 ) |
22 |
21 |
23 from . import ( |
22 from . import ( |
24 error, |
23 error, |
384 def colwidth(s: bytes) -> int: |
383 def colwidth(s: bytes) -> int: |
385 """Find the column width of a string for display in the local encoding""" |
384 """Find the column width of a string for display in the local encoding""" |
386 return ucolwidth(s.decode(_sysstr(encoding), 'replace')) |
385 return ucolwidth(s.decode(_sysstr(encoding), 'replace')) |
387 |
386 |
388 |
387 |
389 def ucolwidth(d: Text) -> int: |
388 def ucolwidth(d: str) -> int: |
390 """Find the column width of a Unicode string for display""" |
389 """Find the column width of a Unicode string for display""" |
391 eaw = getattr(unicodedata, 'east_asian_width', None) |
390 eaw = getattr(unicodedata, 'east_asian_width', None) |
392 if eaw is not None: |
391 if eaw is not None: |
393 return sum([eaw(c) in _wide and 2 or 1 for c in d]) |
392 return sum([eaw(c) in _wide and 2 or 1 for c in d]) |
394 return len(d) |
393 return len(d) |