[commands] Fix ext.commands help page full-width indentation

add _string_width function to util. Changed string width calculate
function from len() to util function _string_width().
This commit is contained in:
cod
2019-02-06 09:24:49 +09:00
committed by Rapptz
parent e53c85110f
commit d107f485a5
2 changed files with 13 additions and 3 deletions

View File

@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE.
import array
import asyncio
import unicodedata
from base64 import b64encode
from bisect import bisect_left
import datetime
@ -39,6 +40,7 @@ import warnings
from .errors import InvalidArgument
DISCORD_EPOCH = 1420070400000
UNICODE_WIDE_CHAR_TYPE = u"WFA"
class cached_property:
def __init__(self, function):
@ -324,3 +326,10 @@ class SnowflakeList(array.array):
def has(self, element):
i = bisect_left(self, element)
return i != len(self) and self[i] == element
def _string_width(string):
"""Returns string's width."""
width = 0
for char in string:
width += 2 if unicodedata.east_asian_width(char) in UNICODE_WIDE_CHAR_TYPE else 1
return width