From 0f9d2beb093372dc9dd7ff6f5ac10fbc122cb0ba Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 23 Sep 2023 23:07:19 +0200 Subject: [PATCH] Add text_kwargs support to EvMore.msg. Resolve #3273 --- CHANGELOG.md | 3 +++ docs/source/Coding/Changelog.md | 6 ++++++ evennia/commands/default/help.py | 12 ++++++++---- evennia/utils/evmore.py | 15 +++++++++++---- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 926fea3995..ffe4452125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Main branch +- [Feature][issue3273]: Allow passing `text_kwargs` kwarg to `EvMore.msg` in order to expand + the outputfunc used for every evmore page. - [Fix][pull3267]: Missing recache step in ObjectSessionHandler (InspectorCaracal) - [Fix][pull3270]: Evennia is its own MSSP family now, so we should return that instead of 'Custom' (InspectorCaracal) @@ -16,6 +18,7 @@ [pull3270]: https://github.com/evennia/evennia/pull/3270 [pull3274]: https://github.com/evennia/evennia/pull/3274 [issue3272]: https://github.com/evennia/evennia/issues/3272 +[issue3273]: https://github.com/evennia/evennia/issues/3273 ## Evennia 2.3.0 diff --git a/docs/source/Coding/Changelog.md b/docs/source/Coding/Changelog.md index 84a8afba69..ffe4452125 100644 --- a/docs/source/Coding/Changelog.md +++ b/docs/source/Coding/Changelog.md @@ -2,17 +2,23 @@ ## Main branch +- [Feature][issue3273]: Allow passing `text_kwargs` kwarg to `EvMore.msg` in order to expand + the outputfunc used for every evmore page. - [Fix][pull3267]: Missing recache step in ObjectSessionHandler (InspectorCaracal) - [Fix][pull3270]: Evennia is its own MSSP family now, so we should return that instead of 'Custom' (InspectorCaracal) - [Fix][pull3274]: Traceback when creating objects with initial nattributes (InspectorCaracal) +- [Fix][issue3272]: Make sure `ScriptHandler.add` does not fail if passed an + instantiated script. - Docs: Typo fixes and starting earlier with explaining how to add to the default cmdsets. [pull3267]: https://github.com/evennia/evennia/pull/3267 [pull3270]: https://github.com/evennia/evennia/pull/3270 [pull3274]: https://github.com/evennia/evennia/pull/3274 +[issue3272]: https://github.com/evennia/evennia/issues/3272 +[issue3273]: https://github.com/evennia/evennia/issues/3273 ## Evennia 2.3.0 diff --git a/evennia/commands/default/help.py b/evennia/commands/default/help.py index 4f31f0ab24..4b8cdccbed 100644 --- a/evennia/commands/default/help.py +++ b/evennia/commands/default/help.py @@ -101,11 +101,12 @@ class CmdHelp(COMMAND_DEFAULT_CLASS): # should topics disply their help entry when clicked clickable_topics = HELP_CLICKABLE_TOPICS - def msg_help(self, text): + def msg_help(self, text, **kwargs): """ messages text to the caller, adding an extra oob argument to indicate that this is a help command result and could be rendered in a separate - help window + help window. + """ if type(self).help_more: usemore = True @@ -122,7 +123,11 @@ class CmdHelp(COMMAND_DEFAULT_CLASS): pass if usemore: - evmore.msg(self.caller, text, session=self.session) + # adding the 'text_kwargs' keyword means it will be sent with the text outputfunc + # for every page. + evmore.msg( + self.caller, text, session=self.session, text_kwargs={"type": "help"}, **kwargs + ) return self.msg(text=(text, {"type": "help"})) @@ -685,7 +690,6 @@ class CmdHelp(COMMAND_DEFAULT_CLASS): # the subtopics is a list describing the path through the subtopic_map. for subtopic_query in subtopics: - if subtopic_query not in subtopic_map: # exact match failed. Try startswith-match fuzzy_match = False diff --git a/evennia/utils/evmore.py b/evennia/utils/evmore.py index 7d445bec98..f989b6d8b7 100644 --- a/evennia/utils/evmore.py +++ b/evennia/utils/evmore.py @@ -155,7 +155,6 @@ class EvMore(object): page_formatter=str, **kwargs, ): - """ Initialization of the EvMore pager. @@ -191,7 +190,11 @@ class EvMore(object): the caller when the more page exits. Note that this will be using whatever cmdset the user had *before* the evmore pager was activated (so none of the evmore commands will be available when this is run). - kwargs (any, optional): These will be passed on to the `caller.msg` method. + kwargs (any, optional): These will be passed on to the `caller.msg` method. Notably, + one can pass additional outputfuncs this way. There is one special kwarg: + - text_kwargs - extra kwargs to pass with the text outputfunc, e.g. + `text_kwargs={"type": "help"} would result to each page being sent + to `msg` as `text=(pagetxt, {"type": "help"})`. Examples: @@ -233,6 +236,9 @@ class EvMore(object): self.exit_on_lastpage = exit_on_lastpage self.exit_cmd = exit_cmd self._exit_msg = _("|xExited pager.|n") + + self._text_kwargs = kwargs.pop("text_kwargs", {}) + self._kwargs = kwargs self._data = None @@ -276,10 +282,11 @@ class EvMore(object): if not sessions: self.page_quit() return - # this must be an 'is', not == check + # this must be an 'is' check, not an == check if not any(ses for ses in sessions if self._session is ses): self._session = sessions[0] - self._caller.msg(text=page, session=self._session, **self._kwargs) + text_outputfunc = (page, (), self._text_kwargs) + self._caller.msg(text=text_outputfunc, session=self._session, **self._kwargs) def page_top(self): """