Skip to main content

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
  • Esc cancellation returning None

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rich_inquirer-0.1.9.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rich_inquirer-0.1.9-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file rich_inquirer-0.1.9.tar.gz.

File metadata

  • Download URL: rich_inquirer-0.1.9.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for rich_inquirer-0.1.9.tar.gz
Algorithm Hash digest
SHA256 710189712dedebe6293fb1db327dc3a81e18cf2c9f07d871c5240070ff79dfc8
MD5 f72337d69ed44066559bd48e45a7d848
BLAKE2b-256 68cc924822b426c22fc809371ea1a54382f05e49a61d913f00de270b4489e4f7

See more details on using hashes here.

File details

Details for the file rich_inquirer-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: rich_inquirer-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for rich_inquirer-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 dbda1f173f94ad2f053e00bdb7b71e94342634808b84d03138e2e0989cee4c03
MD5 05be5bd42654ce707d7549af6eb19ab8
BLAKE2b-256 bbc87f0457925ae52e86cd7f1c138c6719e652da80a5764f312ed263987a84fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page