Skip to content

Commit

Permalink
Merge pull request #1634 from schneiderfelipe/master
Browse files Browse the repository at this point in the history
Mention the usage of Python's builtin readline module in the documentation
  • Loading branch information
willmcgugan authored Nov 7, 2021
2 parents e3369b0 + 747e55b commit a597c0b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
"sphinx.ext.autosectionlabel",
"sphinx_copybutton",
]
Expand Down
4 changes: 3 additions & 1 deletion docs/source/console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ The :meth:`~rich.console.Console.print` method has a boolean ``crop`` argument.
Input
-----

The console class has an :meth:`~rich.console.Console.input` which works in the same way as Python's builtin ``input()`` method, but can use anything that Rich can print as a prompt. For example, here's a colorful prompt with an emoji::
The console class has an :meth:`~rich.console.Console.input` method which works in the same way as Python's builtin :func:`input` function, but can use anything that Rich can print as a prompt. For example, here's a colorful prompt with an emoji::

from rich.console import Console
console = Console()
console.input("What is [i]your[/i] [bold red]name[/]? :smiley: ")

If Python's builtin :mod:`readline` module is previously loaded, elaborate line editing and history features will be available.

Exporting
---------

Expand Down
2 changes: 1 addition & 1 deletion docs/source/prompt.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Prompt
======

Rich has a number of :class:`~rich.prompt.Prompt` classes which ask a user for input and loop until a valid response is received. Here's a simple example::
Rich has a number of :class:`~rich.prompt.Prompt` classes which ask a user for input and loop until a valid response is received (they all use the :ref:`Console API<Input>` internally). Here's a simple example::

>>> from rich.prompt import Prompt
>>> name = Prompt.ask("Enter your name")
Expand Down
2 changes: 2 additions & 0 deletions rich/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,8 @@ def input(
) -> str:
"""Displays a prompt and waits for input from the user. The prompt may contain color / style.
It works in the same way as Python's builtin :func:`input` function and provides elaborate line editing and history features if Python's builtin :mod:`readline` module is previously loaded.
Args:
prompt (Union[str, Text]): Text to render in the prompt.
markup (bool, optional): Enable console markup (requires a str prompt). Defaults to True.
Expand Down

0 comments on commit a597c0b

Please sign in to comment.