Interactive CLI prompts using Rich and readchar, inspired by python-inquirer
Project description
rich-inquirer
Interactive CLI prompts using Rich and readchar, inspired by python-inquirer.
Features
- Text input with password masking
- Select and fuzzy select prompts
- Confirmation prompts
- Prompt chaining with
PromptContext Esccancellation returningNone
Install
pip install rich-inquirer
Usage
from rich_inquirer.prompt import TextPrompt, SelectPrompt, ConfirmPrompt, FuzzyPrompt
name = TextPrompt("What's your name?").ask()
language = SelectPrompt("Choose a language:", ["Python", "Go", "Rust"]).ask()
confirmed = ConfirmPrompt("Continue?", default=True).ask()
match = FuzzyPrompt("Search language:", ["Python", "TypeScript", "Rust"]).ask()
The prompt classes are also available from the top-level package:
from rich_inquirer import TextPrompt
Use Choice when the displayed label should differ from the returned value.
from rich_inquirer.base import Choice
from rich_inquirer.prompt import SelectPrompt
choice = SelectPrompt(
"Choose a language:",
[
Choice("py", name="Python"),
Choice("rs", name="Rust"),
],
).ask()
PromptContext
from rich_inquirer.context import PromptContext
from rich_inquirer.prompt import TextPrompt, SelectPrompt, ConfirmPrompt
context = PromptContext()
context.add("name", TextPrompt("Enter your name:"))
context.add("language", SelectPrompt("Choose language:", ["Python", "Go", "Rust"]))
context.add("confirm", ConfirmPrompt("Continue?", default=True))
results = context.run()
print(results)
If a prompt is cancelled with Esc, PromptContext.run() stops and returns the results collected so far.
Development
pip install -e ".[dev]"
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rich_inquirer-0.1.7.tar.gz.
File metadata
- Download URL: rich_inquirer-0.1.7.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
486d3534b2539cce0b94f81e901c951be26948c24d27feeaa99fcaa326f320b0
|
|
| MD5 |
efb16fcae54567d2af83c703a6dfdc94
|
|
| BLAKE2b-256 |
1f1f9e8006e50f0edad5b3f0ba46c24e79c4195c0712905e3a82f05f50f39c8e
|
File details
Details for the file rich_inquirer-0.1.7-py3-none-any.whl.
File metadata
- Download URL: rich_inquirer-0.1.7-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3960cdf4144c206ce2202fd815f35087334913d3eb8d712eb5da017c3a415ebb
|
|
| MD5 |
1de433c8ec6cae73821ab9204753fd1f
|
|
| BLAKE2b-256 |
b2b8fee8f93bd9878d534dfe48a141a423d43fdceea0aaf7e8c5712d2adb9044
|