From d107f485a5ab0b571e2fb7c7b1f464e1060151ba Mon Sep 17 00:00:00 2001 From: cod Date: Wed, 6 Feb 2019 09:24:49 +0900 Subject: [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(). --- discord/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'discord/utils.py') diff --git a/discord/utils.py b/discord/utils.py index f20274f3..b581607b 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -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 -- cgit v1.2.3