Skip to content

Commit

Permalink
Fix message function not working CITGuru#96
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelsherazi committed Nov 13, 2020
1 parent 7485a1f commit c90095f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions PyInquirer/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from prompt_toolkit.application import Application



def prompt(questions, answers=None, **kwargs):
from . import prompts

Expand Down Expand Up @@ -36,6 +35,10 @@ def prompt(questions, answers=None, **kwargs):
if choices is not None and callable(choices):
question['choices'] = choices(answers)

message = question.get('message')
if message is not None and callable(message):
question['message'] = message(answers)

_kwargs = {}
_kwargs.update(kwargs)
_kwargs.update(question)
Expand All @@ -56,12 +59,12 @@ def prompt(questions, answers=None, **kwargs):
'Problem in \'when\' check of %s question: %s' %
(name, e))
else:
raise ValueError('\'when\' needs to be function that ' \
raise ValueError('\'when\' needs to be function that '
'accepts a dict argument')
if filter:
# at least a little sanity check!
if not callable(question['filter']):
raise ValueError('\'filter\' needs to be function that ' \
raise ValueError('\'filter\' needs to be function that '
'accepts an argument')

if callable(question.get('default')):
Expand All @@ -70,7 +73,6 @@ def prompt(questions, answers=None, **kwargs):
with pt_patch_stdout() if patch_stdout else _dummy_context_manager():
result = getattr(prompts, type_).question(message, **_kwargs)


if isinstance(result, PromptSession):
answer = result.prompt()
elif isinstance(result, Application):
Expand Down Expand Up @@ -106,6 +108,7 @@ def prompt(questions, answers=None, **kwargs):
return {}
return answers


@contextmanager
def _dummy_context_manager():
yield
Expand Down

0 comments on commit c90095f

Please sign in to comment.