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

Uploaded Python 3

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

Hashes for rich_inquirer-0.1.7.tar.gz
Algorithm Hash digest
SHA256 486d3534b2539cce0b94f81e901c951be26948c24d27feeaa99fcaa326f320b0
MD5 efb16fcae54567d2af83c703a6dfdc94
BLAKE2b-256 1f1f9e8006e50f0edad5b3f0ba46c24e79c4195c0712905e3a82f05f50f39c8e

See more details on using hashes here.

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

Hashes for rich_inquirer-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3960cdf4144c206ce2202fd815f35087334913d3eb8d712eb5da017c3a415ebb
MD5 1de433c8ec6cae73821ab9204753fd1f
BLAKE2b-256 b2b8fee8f93bd9878d534dfe48a141a423d43fdceea0aaf7e8c5712d2adb9044

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