Add text_kwargs support to EvMore.msg. Resolve #3273

This commit is contained in:
Griatch 2023-09-23 23:07:19 +02:00
parent 808bde0c7c
commit 0f9d2beb09
4 changed files with 28 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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):
"""