better-rich-prompts

Improved prompts for rich.


License
MIT
Install
pip install better-rich-prompts==1.0.2

Documentation

Supported Python Versions PyPI version

Downloads

English readme

better-rich-prompts is a Python extension library for Rich.

This Library makes it easy to use lists and dictionaries as choices for prompt.ask .

Compatibility

This library should work

Installing

python -m pip install better-rich-prompts

Using List Prompt

Example 1 - Using list of dictionaries

from better_rich_prompts.prompt import ListPrompt

choices = [
    {"name": "english", "language_code": "en"},
    {"name": "spanish", "language_code": "es"},
    {"name":"french","language_code":"fr"},
]
ListPrompt.ask("Select a language", choices, choice_key="name")

ListPrompt Example

Example 2 - Using list of strings

from better_rich_prompts.prompt import ListPrompt

choices = ["en", "es", "fr"]
ListPrompt.ask("Select a language", choices,default="en")

ListPrompt Example

Example 3 - Using list of custom objects

from better_rich_prompts.prompt import ListPrompt

class Language:
    def __init__(self, name, code):
        self.name = name
        self.code = code


choices = [
    Language("english", "en"),
    Language("spanish", "es"),
    Language("french", "fr"),
]
ListPrompt.ask(
    "Select a language", choices, default="en", choice_key=lambda c: c.code
)

ListPrompt Example

Using Dict Prompt

from better_rich_prompts.prompt import DictPrompt

choices = {"en":"english","es":"spanish","fr":"french"}
DictPrompt.ask("Select a language", choices)

ListPrompt Example