Skip to content

Fix message function not working #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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