mirror of
https://github.com/evennia/evennia.git
synced 2026-04-07 00:45:22 +02:00
Extended get_input to accept *args & **kwargs
Calling get_input with args and kwargs passes them to the callback function. Does not affect previous use so no changed required to existing code.
This commit is contained in:
parent
7e8e47b3b3
commit
4327bc48d3
1 changed files with 6 additions and 2 deletions
|
|
@ -894,9 +894,11 @@ class CmdGetInput(Command):
|
|||
|
||||
caller.ndb._getinput._session = self.session
|
||||
prompt = caller.ndb._getinput._prompt
|
||||
args = caller.ndb._getinput._args
|
||||
kwargs = caller.ndb._getinput._kwargs
|
||||
result = self.raw_string.strip() # we strip the ending line break caused by sending
|
||||
|
||||
ok = not callback(caller, prompt, result)
|
||||
ok = not callback(caller, prompt, result, *args, **kwargs)
|
||||
if ok:
|
||||
# only clear the state if the callback does not return
|
||||
# anything
|
||||
|
|
@ -930,7 +932,7 @@ class _Prompt(object):
|
|||
pass
|
||||
|
||||
|
||||
def get_input(caller, prompt, callback, session=None):
|
||||
def get_input(caller, prompt, callback, session=None, *args, **kwargs):
|
||||
"""
|
||||
This is a helper function for easily request input from
|
||||
the caller.
|
||||
|
|
@ -981,6 +983,8 @@ def get_input(caller, prompt, callback, session=None):
|
|||
caller.ndb._getinput._callback = callback
|
||||
caller.ndb._getinput._prompt = prompt
|
||||
caller.ndb._getinput._session = session
|
||||
caller.ndb._getinput._args = args
|
||||
caller.ndb._getinput._kwargs = kwargs
|
||||
caller.cmdset.add(InputCmdSet)
|
||||
caller.msg(prompt, session=session)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue