Skip to main content

Prompt toolkit for console interaction

Project description

NonePrompt

Prompt toolkit for console interaction.

Typing is fully supported. Async is also supported!

Installation

pip install noneprompt

Prompt Usage

Input

from noneprompt import InputPrompt

InputPrompt("What is your name?", validator=lambda string: True).prompt()
await InputPrompt("What is your name?", validator=lambda string: True).prompt_async()

Confirm

from noneprompt import ConfirmPrompt

ConfirmPrompt("Are you sure?", default_choice=False).prompt()
await ConfirmPrompt("Are you sure?", default_choice=False).prompt_async()

List

from noneprompt import ListPrompt, Choice

ListPrompt("What is your favorite color?", choices=[Choice("Red"), Choice("Blue")]).prompt()
await ListPrompt("What is your favorite color?", choices=[Choice("Red"), Choice("Blue")]).prompt_async()

Checkbox

from noneprompt import CheckboxPrompt, Choice

CheckboxPrompt("Choose your favorite colors", choices=[Choice("Red"), Choice("Blue")]).prompt()
await CheckboxPrompt("Choose your favorite colors", choices=[Choice("Red"), Choice("Blue")]).prompt_async()

Choice Data

You can add data to choices. Result type can be inferred from the data type.

from noneprompt import ListPrompt, Choice

result: Choice[str] = ListPrompt(
    "What is your favorite color?",
    choices=[
        Choice("Red", data="#FF0000"),
        Choice("Blue", data="#0000FF"),
    ],
).prompt()
print(result.data)

Defaults and Cancellation

from noneprompt import InputPrompt

result = InputPrompt("Press Ctrl-C to cancel.").prompt(default="Cancelled")
assert result == "Cancelled"
from noneprompt import InputPrompt, CancelledError

try:
    InputPrompt("Press Ctrl-C to cancel.").prompt()
except CancelledError:
    # Do something
    pass

Style Guide

See the docstring of prompt classes for more information.

from noneprompt import InputPrompt
from prompt_toolkit.styles import Style

InputPrompt("What is your name?").prompt(style=Style([("input": "#ffffff"), ("answer": "bold")]))

Disable ansi colors:

from noneprompt import InputPrompt

InputPrompt("What is your name?").prompt(no_ansi=True)

Try from command line

noneprompt -h

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

noneprompt-0.1.9.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

noneprompt-0.1.9-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: noneprompt-0.1.9.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.6 Linux/5.15.0-1033-azure

File hashes

Hashes for noneprompt-0.1.9.tar.gz
Algorithm Hash digest
SHA256 338b8bb89a8d22ef35f1dedb3aa7c1b228cf139973bdc43c5ffc3eef64457db9
MD5 5e7577c3a8555adacb0cfde45c6c7dc8
BLAKE2b-256 ff95bede689ceb60b9d6cea4937db8a0ad53026b41dd00bea58e007cd2653fd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: noneprompt-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.6 Linux/5.15.0-1033-azure

File hashes

Hashes for noneprompt-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 a54f1e6a19a3da2dedf7f365f80420e9ae49326a0ffe60a8a9c7afdee6b6eeb3
MD5 9d28ce3af49e7c2437342ccb12cb0bb7
BLAKE2b-256 49419c89a69e366bff606fdbfd75386f0806c0f191c88cbbf60da381e3c61717

See more details on using hashes here.

Supported by

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