Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 10 additions & 11 deletions docs/pages/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Safe

The following are safe (capture keyboard interrupts):

* :meth:`~questionary.prompt`;
* :func:`~questionary.safe_prompt`;

* :attr:`~questionary.Form.ask` on :class:`~questionary.Form` (returned by
:meth:`~questionary.form`);
Expand All @@ -121,7 +121,7 @@ Here is an example:

# Questionary handles keyboard interrupt and returns `None` if the
# user hits e.g. `Ctrl+C`
prompt(...)
safe_prompt(...)

Unsafe
******
Expand All @@ -136,7 +136,7 @@ The following are unsafe (do not catch keyboard interrupts):
* :attr:`~questionary.Question.unsafe_ask` on :class:`~questionary.Question`,
which is returned by the various prompt functions (e.g. :meth:`~questionary.text`,
:meth:`~questionary.checkbox`).

As a caller you must handle keyboard interrupts yourself
when calling these methods. Here is an example:

Expand Down Expand Up @@ -252,7 +252,7 @@ them using a configuration dictionary:

.. code-block:: python3

from questionary import prompt
from questionary import safe_prompt

questions = [
{
Expand All @@ -268,9 +268,9 @@ them using a configuration dictionary:
}
]

answers = prompt(questions)
answers = safe_prompt(questions)

The questions will be prompted one after another and ``prompt`` will return
The questions will be prompted one after the other and ``safe_prompt`` will return
as soon as all of them are answered. The returned ``answers``
will be a dictionary containing the responses, e.g.

Expand Down Expand Up @@ -314,10 +314,9 @@ add the following optional parameters:

``filter`` (optional)
Receive the user input and return the filtered value to be
used inside the program.
used inside the program.

Further information can be found at the :class:`questionary.prompt`
documentation.
Further information can be found in the :func:`~questionary.safe_prompt` documentation.

.. _random_label:

Expand Down Expand Up @@ -345,14 +344,14 @@ Depending on the route the user took, the result will look like the following:

.. code-block:: python3

{
{
'conditional_step': False,
'second_question': 'Test input' # Free form text
}

.. code-block:: python3

{
{
'conditional_step': True,
'next_question': 'questionary',
'second_question': 'Test input' # Free form text
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ API Reference

.. automethod:: questionary::form

.. automethod:: questionary::prompt
.. automethod:: questionary::safe_prompt

.. automethod:: questionary::unsafe_prompt
4 changes: 2 additions & 2 deletions docs/pages/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The printed output will have the following format:

{'first': True, 'second': 'item2'}

The :meth:`~questionary.prompt` function also allows you to ask a
The :func:`~questionary.safe_prompt` function also allows you to ask a
collection of questions, however instead of taking :class:`~questionary.Question`
instances, it takes a dictionary:

Expand All @@ -105,7 +105,7 @@ instances, it takes a dictionary:
},
]

questionary.prompt(questions)
questionary.safe_prompt(questions)

The format of the returned answers is the same as the one for
:meth:`~questionary.form`. You can find more details on the configuration
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced_workflow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pprint import pprint

from questionary import Separator
from questionary import prompt
from questionary import safe_prompt


def ask_dictstyle(**kwargs):
Expand Down Expand Up @@ -51,7 +51,7 @@ def ask_dictstyle(**kwargs):
"when": lambda x: x["second_question"] == "other",
},
]
return prompt(questions, **kwargs)
return safe_prompt(questions, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/autocomplete_ants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from examples import custom_style_fancy
from questionary import ValidationError
from questionary import Validator
from questionary import prompt
from questionary import safe_prompt


class PolyergusValidator(Validator):
Expand Down Expand Up @@ -81,7 +81,7 @@ def ask_dictstyle(**kwargs):
}
]

return prompt(questions, style=custom_style_fancy, **kwargs)
return safe_prompt(questions, style=custom_style_fancy, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/checkbox_separators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from examples import custom_style_dope
from questionary import Choice
from questionary import Separator
from questionary import prompt
from questionary import safe_prompt


def ask_pystyle(**kwargs):
Expand Down Expand Up @@ -48,7 +48,7 @@ def ask_dictstyle(**kwargs):
}
]

return prompt(questions, style=custom_style_dope, **kwargs)
return safe_prompt(questions, style=custom_style_dope, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/confirm_continue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import questionary
from examples import custom_style_dope
from questionary import prompt
from questionary import safe_prompt


def ask_pystyle(**kwargs):
Expand All @@ -29,7 +29,7 @@ def ask_dictstyle(**kwargs):
}
]

return prompt(questions, style=custom_style_dope, **kwargs)
return safe_prompt(questions, style=custom_style_dope, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/dependent_selects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pprint import pprint

from questionary import prompt
from questionary import safe_prompt

OPTIONS = {"key1": ["k1v1", "k1v2"], "key2": ["k2v1", "k2v2"]}

Expand All @@ -20,7 +20,7 @@ def ask_dictstyle(**kwargs):
"choices": lambda x: OPTIONS[x["key"]],
},
]
return prompt(questions, **kwargs)
return safe_prompt(questions, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/password_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import questionary
from examples import custom_style_dope
from questionary import prompt
from questionary import safe_prompt


def ask_pystyle(**kwargs):
Expand All @@ -24,7 +24,7 @@ def ask_dictstyle(**kwargs):
{"type": "password", "message": "Enter your git password", "name": "password"}
]

return prompt(questions, style=custom_style_dope, **kwargs)
return safe_prompt(questions, style=custom_style_dope, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/rawselect_separator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import questionary
from examples import custom_style_dope
from questionary import Separator
from questionary import prompt
from questionary import safe_prompt


def ask_pystyle(**kwargs):
Expand Down Expand Up @@ -45,7 +45,7 @@ def ask_dictstyle(**kwargs):
},
]

return prompt(questions, style=custom_style_dope, **kwargs)
return safe_prompt(questions, style=custom_style_dope, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/select_restaurant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from examples import custom_style_dope
from questionary import Choice
from questionary import Separator
from questionary import prompt
from questionary import safe_prompt


def ask_pystyle(**kwargs):
Expand Down Expand Up @@ -49,7 +49,7 @@ def ask_dictstyle(**kwargs):
}
]

return prompt(questions, style=custom_style_dope, **kwargs)
return safe_prompt(questions, style=custom_style_dope, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/select_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from examples import custom_style_dope
from questionary import Choice
from questionary import Separator
from questionary import prompt
from questionary import safe_prompt


def ask_pystyle(**kwargs):
Expand Down Expand Up @@ -55,7 +55,7 @@ def ask_dictstyle(**kwargs):
}
]

return prompt(questions, style=custom_style_dope, **kwargs)
return safe_prompt(questions, style=custom_style_dope, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/text_phone_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from examples import custom_style_dope
from questionary import ValidationError
from questionary import Validator
from questionary import prompt
from questionary import safe_prompt


class PhoneNumberValidator(Validator):
Expand Down Expand Up @@ -50,7 +50,7 @@ def ask_dictstyle(**kwargs):
}
]

return prompt(questions, style=custom_style_dope, **kwargs)
return safe_prompt(questions, style=custom_style_dope, **kwargs)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions questionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from questionary.form import Form
from questionary.form import FormField
from questionary.form import form
from questionary.prompt import prompt
from questionary.prompt import prompt_async
from questionary.prompt import safe_prompt
from questionary.prompt import unsafe_prompt
from questionary.prompt import unsafe_prompt_async

Expand Down Expand Up @@ -44,7 +44,7 @@
# utility methods
"print",
"form",
"prompt",
"safe_prompt",
"prompt_async",
"unsafe_prompt",
"unsafe_prompt_async",
Expand Down
4 changes: 2 additions & 2 deletions questionary/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async def prompt_async(
return {}


def prompt(
def safe_prompt(
questions: Union[Dict[str, Any], Iterable[Mapping[str, Any]]],
answers: Optional[Mapping[str, Any]] = None,
patch_stdout: bool = False,
Expand Down Expand Up @@ -229,6 +229,7 @@ def prompt(
are printing to stdout.

kbi_msg: The message to be printed on a keyboard interrupt.

true_color: Use true color output.

color_depth: Color depth to use. If ``true_color`` is set to true then this
Expand All @@ -244,7 +245,6 @@ def prompt(
Returns:
Dictionary of question answers.
"""

try:
return unsafe_prompt(questions, answers, patch_stdout, true_color, **kwargs)
except KeyboardInterrupt:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_prompt.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import pytest

from questionary.prompt import PromptParameterException
from questionary.prompt import prompt
from questionary.prompt import safe_prompt
from tests.utils import patched_prompt


def test_missing_message():
with pytest.raises(PromptParameterException):
prompt([{"type": "confirm", "name": "continue", "default": True}])
safe_prompt([{"type": "confirm", "name": "continue", "default": True}])


def test_missing_type():
with pytest.raises(PromptParameterException):
prompt(
safe_prompt(
[
{
"message": "Do you want to continue?",
Expand All @@ -25,7 +25,7 @@ def test_missing_type():

def test_missing_name():
with pytest.raises(PromptParameterException):
prompt(
safe_prompt(
[
{
"type": "confirm",
Expand All @@ -38,7 +38,7 @@ def test_missing_name():

def test_invalid_question_type():
with pytest.raises(ValueError):
prompt(
safe_prompt(
[
{
"type": "mytype",
Expand All @@ -53,7 +53,7 @@ def test_invalid_question_type():
def test_missing_print_message():
"""Test 'print' raises exception if missing 'message'"""
with pytest.raises(PromptParameterException):
prompt(
safe_prompt(
[
{
"name": "test",
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from prompt_toolkit.input.defaults import create_pipe_input
from prompt_toolkit.output import DummyOutput

from questionary import prompt
from questionary import safe_prompt
from questionary.prompts import prompt_by_name
from questionary.utils import is_prompt_toolkit_3

Expand Down Expand Up @@ -72,7 +72,7 @@ def patched_prompt(questions, text, **kwargs):
def run(inp):
# noinspection PyUnresolvedReferences
inp.send_text(text)
result = prompt(questions, input=inp, output=DummyOutput(), **kwargs)
result = safe_prompt(questions, input=inp, output=DummyOutput(), **kwargs)
return result

return execute_with_input_pipe(run)
Expand Down
Loading