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.10.tar.gz (9.9 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.10-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rich_inquirer-0.1.10.tar.gz
  • Upload date:
  • Size: 9.9 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.10.tar.gz
Algorithm Hash digest
SHA256 3ded128f2f38f1f71d14455fd58a954c317bed512a6904d2e8281c26246bbcf3
MD5 1843e4f05e45d773e3c37ff87aa964c0
BLAKE2b-256 dea55f3445234489fc9bdf87c640ffa0c2686f040100db12fd0e664e74d76af8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rich_inquirer-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 10.0 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.10-py3-none-any.whl
Algorithm Hash digest
SHA256 bbb52d109d5a54c7b556518e29cc8008dfb41b9c4877bd0ec486ffb9da11e29d
MD5 0cc52be1b32fffea452c16fbe1a0b5c2
BLAKE2b-256 b4fec42b4e5db9c087ac06c9fd61fe859449e38d6b4489fc23a9a1b0681de249

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