CmdHelp clickable topics
Added clickable topics throughout CmdHelp. unit test evennia.commands.default.tests.TestHelp passes.
This commit is contained in:
parent
a85f8995b3
commit
6cf1f65722
1 changed files with 61 additions and 23 deletions
|
|
@ -97,6 +97,9 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
# separator between subtopics:
|
# separator between subtopics:
|
||||||
subtopic_separator_char = r"/"
|
subtopic_separator_char = r"/"
|
||||||
|
|
||||||
|
# should topics disply their help entry when clicked
|
||||||
|
clickable_topics = True
|
||||||
|
|
||||||
def msg_help(self, text):
|
def msg_help(self, text):
|
||||||
"""
|
"""
|
||||||
messages text to the caller, adding an extra oob argument to indicate
|
messages text to the caller, adding an extra oob argument to indicate
|
||||||
|
|
@ -121,21 +124,22 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
self.msg(text=(text, {"type": "help"}))
|
self.msg(text=(text, {"type": "help"}))
|
||||||
|
|
||||||
def format_help_entry(self, topic="", help_text="", aliases=None, suggested=None,
|
def format_help_entry(self, topic="", help_text="", aliases=None, suggested=None,
|
||||||
subtopics=None):
|
subtopics=None, click_topics=True):
|
||||||
"""
|
"""This visually formats the help entry.
|
||||||
This visually formats the help entry.
|
|
||||||
This method can be overriden to customize the way a help
|
This method can be overriden to customize the way a help
|
||||||
entry is displayed.
|
entry is displayed.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
title (str): The title of the help entry.
|
title (str, optional): The title of the help entry.
|
||||||
help_text (str): Text of the help entry.
|
help_text (str, optional): Text of the help entry.
|
||||||
aliases (list): List of help-aliases (displayed in header).
|
aliases (list, optional): List of help-aliases (displayed in header).
|
||||||
suggested (list): Strings suggested reading (based on title).
|
suggested (list, optional): Strings suggested reading (based on title).
|
||||||
subtopics (list): A list of strings - the subcategories available
|
subtopics (list, optional): A list of strings - the subcategories available
|
||||||
for this entry.
|
for this entry.
|
||||||
|
click_topics (bool, optional): Should help topics be clickable. Default is True.
|
||||||
|
|
||||||
Returns the formatted string, ready to be sent.
|
Returns:
|
||||||
|
help_message (str): Help entry formated for console.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
separator = "|C" + "-" * self.client_width() + "|n"
|
separator = "|C" + "-" * self.client_width() + "|n"
|
||||||
|
|
@ -153,7 +157,13 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
help_text = "\n" + dedent(help_text.strip('\n')) if help_text else ""
|
help_text = "\n" + dedent(help_text.strip('\n')) if help_text else ""
|
||||||
|
|
||||||
if subtopics:
|
if subtopics:
|
||||||
subtopics = [f"|w{topic}/{subtop}|n" for subtop in subtopics]
|
if click_topics:
|
||||||
|
subtopics = [
|
||||||
|
f"|lchelp {topic}/{subtop}|lt|w{topic}/{subtop}|n|le"
|
||||||
|
for subtop in subtopics
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
subtopics = [f"|w{topic}/{subtop}|n" for subtop in subtopics]
|
||||||
subtopics = (
|
subtopics = (
|
||||||
"\n|CSubtopics:|n\n {}".format(
|
"\n|CSubtopics:|n\n {}".format(
|
||||||
"\n ".join(format_grid(subtopics, width=self.client_width())))
|
"\n ".join(format_grid(subtopics, width=self.client_width())))
|
||||||
|
|
@ -162,7 +172,10 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
subtopics = ''
|
subtopics = ''
|
||||||
|
|
||||||
if suggested:
|
if suggested:
|
||||||
suggested = [f"|w{sug}|n" for sug in suggested]
|
if click_topics:
|
||||||
|
suggested = [f"|lchelp {sug}|lt|w{sug}|n|le" for sug in suggested]
|
||||||
|
else:
|
||||||
|
suggested = [f"|w{sug}|n" for sug in suggested]
|
||||||
suggested = (
|
suggested = (
|
||||||
"\n|COther topic suggestions:|n\n{}".format(
|
"\n|COther topic suggestions:|n\n{}".format(
|
||||||
"\n ".join(format_grid(suggested, width=self.client_width())))
|
"\n ".join(format_grid(suggested, width=self.client_width())))
|
||||||
|
|
@ -176,9 +189,9 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
return "\n".join(part.rstrip() for part in partorder if part)
|
return "\n".join(part.rstrip() for part in partorder if part)
|
||||||
|
|
||||||
def format_help_index(self, cmd_help_dict=None, db_help_dict=None, title_lone_category=False):
|
def format_help_index(self, cmd_help_dict=None, db_help_dict=None, title_lone_category=False,
|
||||||
"""
|
click_topics=True):
|
||||||
Output a category-ordered g for displaying the main help, grouped by
|
"""Output a category-ordered g for displaying the main help, grouped by
|
||||||
category.
|
category.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
@ -190,14 +203,15 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
be titled with the category name or not. While pointless in a
|
be titled with the category name or not. While pointless in a
|
||||||
general index, the title should probably show when explicitly
|
general index, the title should probably show when explicitly
|
||||||
listing the category itself.
|
listing the category itself.
|
||||||
|
click_topics (bool, optional): Should help topics be clickable. Default is True.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str: The help index organized into a grid.
|
str: The help index organized into a grid.
|
||||||
|
|
||||||
The input are the
|
Notes
|
||||||
pre-loaded help files for commands and database-helpfiles
|
The input are the pre-loaded help files for commands and database-helpfiles
|
||||||
respectively. You can override this method to return a
|
respectively. You can override this method to return a custom display of the list of
|
||||||
custom display of the list of commands and topics.
|
commands and topics.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def _group_by_category(help_dict):
|
def _group_by_category(help_dict):
|
||||||
|
|
@ -207,7 +221,16 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
if len(help_dict) == 1 and not title_lone_category:
|
if len(help_dict) == 1 and not title_lone_category:
|
||||||
# don't list categories if there is only one
|
# don't list categories if there is only one
|
||||||
for category in help_dict:
|
for category in help_dict:
|
||||||
|
# gather and sort the entries from the help dictionary
|
||||||
entries = sorted(set(help_dict.get(category, [])))
|
entries = sorted(set(help_dict.get(category, [])))
|
||||||
|
|
||||||
|
# make the help topics clickable
|
||||||
|
if click_topics:
|
||||||
|
entries = [
|
||||||
|
f'|lchelp {entry}|lt{entry}|le' for entry in entries
|
||||||
|
]
|
||||||
|
|
||||||
|
# add the entries to the grid
|
||||||
grid.extend(entries)
|
grid.extend(entries)
|
||||||
else:
|
else:
|
||||||
# list the categories
|
# list the categories
|
||||||
|
|
@ -222,7 +245,16 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
)
|
)
|
||||||
verbatim_elements.append(len(grid) - 1)
|
verbatim_elements.append(len(grid) - 1)
|
||||||
|
|
||||||
|
# gather and sort the entries from the help dictionary
|
||||||
entries = sorted(set(help_dict.get(category, [])))
|
entries = sorted(set(help_dict.get(category, [])))
|
||||||
|
|
||||||
|
# make the help topics clickable
|
||||||
|
if click_topics:
|
||||||
|
entries = [
|
||||||
|
f'|lchelp {entry}|lt{entry}|le' for entry in entries
|
||||||
|
]
|
||||||
|
|
||||||
|
# add the entries to the grid
|
||||||
grid.extend(entries)
|
grid.extend(entries)
|
||||||
|
|
||||||
return grid, verbatim_elements
|
return grid, verbatim_elements
|
||||||
|
|
@ -449,6 +481,7 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
"""
|
"""
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
query, subtopics, cmdset = self.topic, self.subtopics, self.cmdset
|
query, subtopics, cmdset = self.topic, self.subtopics, self.cmdset
|
||||||
|
clickable_topics = self.clickable_topics
|
||||||
|
|
||||||
if not query:
|
if not query:
|
||||||
# list all available help entries, grouped by category. We want to
|
# list all available help entries, grouped by category. We want to
|
||||||
|
|
@ -470,7 +503,8 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
|
|
||||||
# generate the index and display
|
# generate the index and display
|
||||||
output = self.format_help_index(cmd_help_by_category,
|
output = self.format_help_index(cmd_help_by_category,
|
||||||
file_db_help_by_category)
|
file_db_help_by_category,
|
||||||
|
click_topics=clickable_topics)
|
||||||
self.msg_help(output)
|
self.msg_help(output)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -526,7 +560,8 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
output = self.format_help_entry(
|
output = self.format_help_entry(
|
||||||
topic=None, # this will give a no-match style title
|
topic=None, # this will give a no-match style title
|
||||||
help_text=help_text,
|
help_text=help_text,
|
||||||
suggested=suggestions
|
suggested=suggestions,
|
||||||
|
click_topics=clickable_topics
|
||||||
)
|
)
|
||||||
|
|
||||||
self.msg_help(output)
|
self.msg_help(output)
|
||||||
|
|
@ -542,7 +577,8 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
if category_lower == topic.help_category]
|
if category_lower == topic.help_category]
|
||||||
output = self.format_help_index({category: cmds_in_category},
|
output = self.format_help_index({category: cmds_in_category},
|
||||||
{category: topics_in_category},
|
{category: topics_in_category},
|
||||||
title_lone_category=True)
|
title_lone_category=True,
|
||||||
|
click_topics=clickable_topics)
|
||||||
self.msg_help(output)
|
self.msg_help(output)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -596,7 +632,8 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
output = self.format_help_entry(
|
output = self.format_help_entry(
|
||||||
topic=topic,
|
topic=topic,
|
||||||
help_text=f"No help entry found for '{checked_topic}'",
|
help_text=f"No help entry found for '{checked_topic}'",
|
||||||
subtopics=subtopic_index
|
subtopics=subtopic_index,
|
||||||
|
click_topics=clickable_topics
|
||||||
)
|
)
|
||||||
self.msg_help(output)
|
self.msg_help(output)
|
||||||
return
|
return
|
||||||
|
|
@ -616,7 +653,8 @@ class CmdHelp(COMMAND_DEFAULT_CLASS):
|
||||||
help_text=help_text,
|
help_text=help_text,
|
||||||
aliases=aliases if not subtopics else None,
|
aliases=aliases if not subtopics else None,
|
||||||
subtopics=subtopic_index,
|
subtopics=subtopic_index,
|
||||||
suggested=suggested
|
suggested=suggested,
|
||||||
|
click_topics=clickable_topics
|
||||||
)
|
)
|
||||||
|
|
||||||
self.msg_help(output)
|
self.msg_help(output)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue