Inject selection in list_node decorator if select kwarg is a string
This commit is contained in:
parent
b571d6fdd4
commit
acc651b2fe
1 changed files with 12 additions and 5 deletions
|
|
@ -1005,10 +1005,12 @@ def list_node(option_generator, select=None, pagesize=10):
|
||||||
Args:
|
Args:
|
||||||
option_generator (callable or list): A list of strings indicating the options, or a callable
|
option_generator (callable or list): A list of strings indicating the options, or a callable
|
||||||
that is called as option_generator(caller) to produce such a list.
|
that is called as option_generator(caller) to produce such a list.
|
||||||
select (callable, option): Will be called as select(caller, menuchoice)
|
select (callable or str, optional): Node to redirect a selection to. Its `**kwargs` will
|
||||||
where menuchoice is the chosen option as a string. Should return the target node to
|
contain the `available_choices` list and `selection` will hold one of the elements in
|
||||||
goto after this selection (or None to repeat the list-node). Note that if this is not
|
that list. If a callable, it will be called as select(caller, menuchoice) where
|
||||||
given, the decorated node must itself provide a way to continue from the node!
|
menuchoice is the chosen option as a string. Should return the target node to goto after
|
||||||
|
this selection (or None to repeat the list-node). Note that if this is not given, the
|
||||||
|
decorated node must itself provide a way to continue from the node!
|
||||||
pagesize (int): How many options to show per page.
|
pagesize (int): How many options to show per page.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
@ -1038,11 +1040,16 @@ def list_node(option_generator, select=None, pagesize=10):
|
||||||
except Exception:
|
except Exception:
|
||||||
caller.msg("|rInvalid choice.|n")
|
caller.msg("|rInvalid choice.|n")
|
||||||
else:
|
else:
|
||||||
if select:
|
if callable(select):
|
||||||
try:
|
try:
|
||||||
return select(caller, selection)
|
return select(caller, selection)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log_trace()
|
logger.log_trace()
|
||||||
|
else:
|
||||||
|
# we assume a string was given, we inject the result into the kwargs
|
||||||
|
# to pass on to the next node
|
||||||
|
kwargs['selection'] = selection
|
||||||
|
return str(select)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _list_node(caller, raw_string, **kwargs):
|
def _list_node(caller, raw_string, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue