[Help] Strip docstrings before shortening them (#4983)

* [Help] Strip docstrings before shortening them

* [Help] Use rstrip instead of full strip
This commit is contained in:
Kreusada 2021-05-19 12:58:48 +01:00 committed by GitHub
parent 53276ea12a
commit 606c2f50ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -380,7 +380,7 @@ class RedHelpFormatter(HelpFormatterABC):
def shorten_line(a_line: str) -> str: def shorten_line(a_line: str) -> str:
if len(a_line) < 70: # embed max width needs to be lower if len(a_line) < 70: # embed max width needs to be lower
return a_line return a_line
return a_line[:67] + "..." return a_line[:67].rstrip() + "..."
subtext = "\n".join( subtext = "\n".join(
shorten_line(f"**{name}** {command.format_shortdoc_for_context(ctx)}") shorten_line(f"**{name}** {command.format_shortdoc_for_context(ctx)}")
@ -410,7 +410,7 @@ class RedHelpFormatter(HelpFormatterABC):
width_gap = discord.utils._string_width(nm) - len(nm) width_gap = discord.utils._string_width(nm) - len(nm)
doc = com.format_shortdoc_for_context(ctx) doc = com.format_shortdoc_for_context(ctx)
if len(doc) > doc_max_width: if len(doc) > doc_max_width:
doc = doc[: doc_max_width - 3] + "..." doc = doc[: doc_max_width - 3].rstrip() + "..."
yield nm, doc, max_width - width_gap yield nm, doc, max_width - width_gap
subtext = "\n".join( subtext = "\n".join(
@ -555,7 +555,7 @@ class RedHelpFormatter(HelpFormatterABC):
def shorten_line(a_line: str) -> str: def shorten_line(a_line: str) -> str:
if len(a_line) < 70: # embed max width needs to be lower if len(a_line) < 70: # embed max width needs to be lower
return a_line return a_line
return a_line[:67] + "..." return a_line[:67].rstrip() + "..."
command_text = "\n".join( command_text = "\n".join(
shorten_line(f"**{name}** {command.format_shortdoc_for_context(ctx)}") shorten_line(f"**{name}** {command.format_shortdoc_for_context(ctx)}")
@ -584,7 +584,7 @@ class RedHelpFormatter(HelpFormatterABC):
width_gap = discord.utils._string_width(nm) - len(nm) width_gap = discord.utils._string_width(nm) - len(nm)
doc = com.format_shortdoc_for_context(ctx) doc = com.format_shortdoc_for_context(ctx)
if len(doc) > doc_max_width: if len(doc) > doc_max_width:
doc = doc[: doc_max_width - 3] + "..." doc = doc[: doc_max_width - 3].rstrip() + "..."
yield nm, doc, max_width - width_gap yield nm, doc, max_width - width_gap
subtext = "\n".join( subtext = "\n".join(
@ -622,7 +622,7 @@ class RedHelpFormatter(HelpFormatterABC):
def shorten_line(a_line: str) -> str: def shorten_line(a_line: str) -> str:
if len(a_line) < 70: # embed max width needs to be lower if len(a_line) < 70: # embed max width needs to be lower
return a_line return a_line
return a_line[:67] + "..." return a_line[:67].rstrip() + "..."
cog_text = "\n".join( cog_text = "\n".join(
shorten_line(f"**{name}** {command.format_shortdoc_for_context(ctx)}") shorten_line(f"**{name}** {command.format_shortdoc_for_context(ctx)}")
@ -655,7 +655,7 @@ class RedHelpFormatter(HelpFormatterABC):
width_gap = discord.utils._string_width(nm) - len(nm) width_gap = discord.utils._string_width(nm) - len(nm)
doc = com.format_shortdoc_for_context(ctx) doc = com.format_shortdoc_for_context(ctx)
if len(doc) > doc_max_width: if len(doc) > doc_max_width:
doc = doc[: doc_max_width - 3] + "..." doc = doc[: doc_max_width - 3].rstrip() + "..."
yield nm, doc, max_width - width_gap yield nm, doc, max_width - width_gap
for cog_name, data in coms: for cog_name, data in coms: