aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcod <[email protected]>2019-02-06 09:24:49 +0900
committerRapptz <[email protected]>2019-02-06 02:15:04 -0500
commitd107f485a5ab0b571e2fb7c7b1f464e1060151ba (patch)
tree432e117992f1bd53ea875c9def100df34545cb40
parentClarified add_listener documentation (diff)
downloaddiscord.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().
-rw-r--r--discord/ext/commands/formatter.py7
-rw-r--r--discord/utils.py9
2 files changed, 13 insertions, 3 deletions
diff --git a/discord/ext/commands/formatter.py b/discord/ext/commands/formatter.py
index ce85e0d3..396eb359 100644
--- a/discord/ext/commands/formatter.py
+++ b/discord/ext/commands/formatter.py
@@ -26,6 +26,7 @@ DEALINGS IN THE SOFTWARE.
import itertools
import inspect
+import discord.utils
from .core import GroupMixin, Command
from .errors import CommandError
@@ -172,7 +173,7 @@ class HelpFormatter:
try:
commands = self.command.all_commands if not self.is_cog() else self.context.bot.all_commands
if commands:
- return max(map(lambda c: len(c.name) if self.show_hidden or not c.hidden else 0, commands.values()))
+ return max(map(lambda c: discord.utils._string_width(c.name) if self.show_hidden or not c.hidden else 0, commands.values()))
return 0
except AttributeError:
return len(self.command.name)
@@ -250,8 +251,8 @@ class HelpFormatter:
if name in command.aliases:
# skip aliases
continue
-
- entry = ' {0:<{width}} {1}'.format(name, command.short_doc, width=max_width)
+ width_gap = discord.utils._string_width(name) - len(name)
+ entry = ' {0:<{width}} {1}'.format(name, command.short_doc, width=max_width-width_gap)
shortened = self.shorten(entry)
self._paginator.add_line(shortened)
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