Skip to main content

Input for command line questions with options

Project description

PromptWithOptions

Command line input with options for Python

Example

from promptwithoptions import (
    set_prompt_defaults,
    promptwithoptions,
)

clr_yellow = "\u001b[33m"
clr_l_green = "\u001b[32;1m"
clr_blue = "\u001b[34m"
clr_l_blue = "\u001b[34;1m"

my_options = ('one', 'two', 'three')

set_prompt_defaults(options_line_color=clr_yellow, options_number_color=clr_l_green, input_line_color=clr_blue, confirm_line_color=clr_l_blue)

promptwithoptions('How many', my_options, default=1, show_confirmation=True)

Available settings

These are all optional named arguments (in this order) of set_prompt_defaults and promptwithoptions.

options: list of available options, without this

data_type: a callable that raises an exception if the input is invalid (e.g. int, bool)

default: default in case of empty input

allow_empty: boolean, if True then prompt doesn't repeat with empty input

allow_multiple: boolean, if True then comma-separated values are accepted

show_confirmation: boolean, if True then the accepted input is reprinted with the selected option (if options are given)

hide_key: boolean, if True the first item of each option doesn't get printed on the screen

hide_questionmark: boolean, if True then '?' is not attached to prompt text (neither a ':' to the confirmation if shown)

no_interaction: boolean, if True default is applied automatically (if given) and no input is required (this is to apply --yes)

options_line_color: if given, options are displayed as a numbered list - this is the colour of the list items

options_number_color: if given, options are displayed as a numbered list - this is the colour of the numbers

input_line_color: as is

confirm_line_color: as is

Setting and resetting defaults

set_prompt_defaults() can be called multiple times.
A default value can be removed (set back to None) when explicitely given like set_prompt_defaults(allow_empty=None). If need argument defaults can be reset by calling reset_defaults (from promptwithoptions import reset_defaults).

Options list

It's a plain list of strings, a list of keys and values or a dict.
If there are keys and values only a key is returned at the end. In that case keys can be stopped from printing by hide_key.

Entering empty value when default is given

Use '-' to explicitely get empty even when default is given and allow_empty=True.

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

promptwithoptions-0.9.2.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

promptwithoptions-0.9.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file promptwithoptions-0.9.2.tar.gz.

File metadata

  • Download URL: promptwithoptions-0.9.2.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.10.10-051010-generic

File hashes

Hashes for promptwithoptions-0.9.2.tar.gz
Algorithm Hash digest
SHA256 aeb15f7ad149e75a79eb162cdb14b3a85fe45a75eb4c525ca3229b52be15932d
MD5 02ccc3aa551df80308f12188db3bb9ea
BLAKE2b-256 8766aac720e60a5dd2cc6aa456552f3dbae018cb5318f79ac6e215c5f0180f09

See more details on using hashes here.

File details

Details for the file promptwithoptions-0.9.2-py3-none-any.whl.

File metadata

  • Download URL: promptwithoptions-0.9.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.10.10-051010-generic

File hashes

Hashes for promptwithoptions-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dddb4d7e9311eed2d0ae093f4f59fa1fd17d9de61d031e149805e75bed1a7f25
MD5 427cb8f481fa656ecf31f5a7e4344606
BLAKE2b-256 6058fa390a1faebd78d6e2b6d1d732e2898e3a2455629bf2d1cf72e15e7ed07d

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