mirror of
https://github.com/Textualize/rich.git
synced 2025-08-04 01:58:24 +00:00
Merge branch 'master' of https://github.com/chthollyphile/rich
This commit is contained in:
commit
74445d76c3
51 changed files with 809 additions and 339 deletions
|
@ -17,10 +17,15 @@
|
|||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
import sys
|
||||
|
||||
import pkg_resources
|
||||
import sphinx_rtd_theme
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
from importlib.metadata import Distribution
|
||||
else:
|
||||
from importlib_metadata import Distribution
|
||||
|
||||
html_theme = "sphinx_rtd_theme"
|
||||
|
||||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
|
||||
|
@ -30,7 +35,7 @@ copyright = "Will McGugan"
|
|||
author = "Will McGugan"
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = pkg_resources.get_distribution("rich").version
|
||||
release = Distribution.from_name("rich").version
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
|
|
@ -55,6 +55,34 @@ Here's a simple example::
|
|||
The ``total`` value associated with a task is the number of steps that must be completed for the progress to reach 100%. A *step* in this context is whatever makes sense for your application; it could be number of bytes of a file read, or number of images processed, etc.
|
||||
|
||||
|
||||
Starting and stopping
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The context manager is recommended if you can use it. If you don't use the context manager, be sure to call :meth:`~rich.progress.Progress.start` to start the progress display, and :meth:`~rich.progress.Progress.stop` to stop it.
|
||||
|
||||
Here's an example that doesn't use the context manager::
|
||||
|
||||
import time
|
||||
|
||||
from rich.progress import Progress
|
||||
|
||||
progress = Progress()
|
||||
progress.start()
|
||||
try:
|
||||
task1 = progress.add_task("[red]Downloading...", total=1000)
|
||||
task2 = progress.add_task("[green]Processing...", total=1000)
|
||||
task3 = progress.add_task("[cyan]Cooking...", total=1000)
|
||||
|
||||
while not progress.finished:
|
||||
progress.update(task1, advance=0.5)
|
||||
progress.update(task2, advance=0.3)
|
||||
progress.update(task3, advance=0.9)
|
||||
time.sleep(0.02)
|
||||
finally:
|
||||
progress.stop()
|
||||
|
||||
Note the use of the try / finally, to ensure that ``stop()`` is called.
|
||||
|
||||
Updating tasks
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -18,6 +18,13 @@ If you supply a list of choices, the prompt will loop until the user enters one
|
|||
>>> from rich.prompt import Prompt
|
||||
>>> name = Prompt.ask("Enter your name", choices=["Paul", "Jessica", "Duncan"], default="Paul")
|
||||
|
||||
By default this is case sensitive, but you can set `case_sensitive=False` to make it case insensitive::
|
||||
|
||||
>>> from rich.prompt import Prompt
|
||||
>>> name = Prompt.ask("Enter your name", choices=["Paul", "Jessica", "Duncan"], default="Paul", case_sensitive=False)
|
||||
|
||||
Now, it would accept "paul" or "Paul" as valid responses.
|
||||
|
||||
In addition to :class:`~rich.prompt.Prompt` which returns strings, you can also use :class:`~rich.prompt.IntPrompt` which asks the user for an integer, and :class:`~rich.prompt.FloatPrompt` for floats.
|
||||
|
||||
The :class:`~rich.prompt.Confirm` class is a specialized prompt which may be used to ask the user a simple yes / no question. Here's an example::
|
||||
|
@ -30,4 +37,4 @@ The Prompt class was designed to be customizable via inheritance. See `prompt.py
|
|||
|
||||
To see some of the prompts in action, run the following command from the command line::
|
||||
|
||||
python -m rich.prompt
|
||||
python -m rich.prompt
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue