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

Uploaded Python 3

File details

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

File metadata

  • Download URL: rich_inquirer-0.1.8.tar.gz
  • Upload date:
  • Size: 9.3 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.8.tar.gz
Algorithm Hash digest
SHA256 6879c8de86d378f52b7cf12ea2659b429830aa5deb2bae5cd152d0d4a621495c
MD5 295df63f07fe28c7c73062d18d162412
BLAKE2b-256 f2003ae554a36e66e555c7f9ccc381523b14ac6b5f8891b01c9e7a5c6c5bae02

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rich_inquirer-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 9.6 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ef5ff42705b26cc9d71302cfd5fef64267a334c386e1b6610bd9122dd8fc611d
MD5 6590843e80bff55df4f4c3689dd306e2
BLAKE2b-256 07005cec6b6b612c4db23c1e5d83132684326059124f22974bf846c6038e6f80

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