diff options
| author | cod <[email protected]> | 2019-02-06 09:24:49 +0900 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-02-06 02:15:04 -0500 |
| commit | d107f485a5ab0b571e2fb7c7b1f464e1060151ba (patch) | |
| tree | 432e117992f1bd53ea875c9def100df34545cb40 /discord/utils.py | |
| parent | Clarified add_listener documentation (diff) | |
| download | discord.py-d107f485a5ab0b571e2fb7c7b1f464e1060151ba.tar.xz discord.py-d107f485a5ab0b571e2fb7c7b1f464e1060151ba.zip | |
[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().
Diffstat (limited to 'discord/utils.py')
| -rw-r--r-- | discord/utils.py | 9 |
1 files changed, 9 insertions, 0 deletions
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 |