Merge pull request #3968 from Sanjays2402/fix/evmenu-dict-helptext

fix(evmenu): format dict helptext per entry
This commit is contained in:
Griatch
2026-07-25 11:17:07 +02:00
committed by GitHub
2 changed files with 28 additions and 2 deletions

View File

@ -1165,12 +1165,17 @@ class EvMenu:
Format the node's help text
Args:
helptext (str): The unformatted help text for the node.
helptext (str or dict): The unformatted help text for the node. A dict
maps a tooltip command to its own help text; each entry is
formatted separately.
Returns:
helptext (str): The formatted help text.
helptext (str or dict): The formatted help text, of the same type as
the input.
"""
if isinstance(helptext, dict):
return {key: self.helptext_formatter(entry) for key, entry in helptext.items()}
return dedent(helptext.strip("\n"), baseline_index=0).rstrip()
def options_formatter(self, optionlist):

View File

@ -373,3 +373,24 @@ class TestEvMenuPersistentReloadRegression(BaseEvenniaTest):
menu_cmdsets = [cmdset for cmdset in self.char1.cmdset.get() if cmdset.key == "menu_cmdset"]
self.assertEqual(len(menu_cmdsets), 1)
self.assertEqual(self.char1.cmdset_storage.count("evennia.utils.evmenu.EvMenuCmdSet"), 1)
def _tooltip_menu_start(caller, raw_string, **kwargs):
return (
"start text",
{"foo": "help about foo", ("bar", "baz"): "help about bar"},
), {"key": "next", "desc": "go next", "goto": "start"}
class TestEvMenuDictHelptext(BaseEvenniaTest):
"""
A node may return its help text as a dict in order to provide per-command
tooltips (issue #3755).
"""
def test_dict_helptext_node(self):
menu = evmenu.EvMenu(self.char1, {"start": _tooltip_menu_start}, session=self.session)
self.assertEqual(
menu.helptext,
{"foo": "help about foo", "bar": "help about bar", "baz": "help about bar"},
)