Documentation for NicePrompts

nice_prompts

nice_prompts package

class nice_prompts.NicePrompt(terminal=<blessed.terminal.Terminal object>)

Bases: object

Make nice prompts to gather input from the user e.g. multiple choice

Parameters:

terminal (blessed.Terminal) – Supply a blessed terminal to use. Defaults to a new blessed terminal

confirm()
multiselection(options, amount=-1, required=1)

Choose some items from a dictionary of options. Keys are availiable options, values are what the function will return if that option is selected

Parameters:
  • options (dict) – A dictionary of options. Keys are availiable options, values are what the function will return if that option is selected

  • amount (int, optional) – The max amount of items the user can select. Leave out for no limit.

  • required (int, optional) – The minimum amount of items the user can select. Defaults to 1.

Returns:

A list of the values from the options dictionary that the user selected

Return type:

list[Object]

number(number_type, start=None, end=None, check=<function NicePrompt.<lambda>>)

The user can enter a number with optional bounds

Parameters:
  • number_type (class) – The class of the number you want the user to enter. e.g. int float

  • start (int, optional) – The minimum number the user can enter. Leave out for no minimum

  • end (int, optional) – The maximum number the user can enter. Leave out for no maximum

  • check (function, optional) – A function that will be passed the number. Should return true or false, which will be used to check if the entered number is valid. You can use this for extra checks e.g. prime numbers

Returns:

The number the user entered

Return type:

type(number_type)

selection(options)

Choose an item from a dictionary of options. Keys are availiable options, values are what the function will return if that option is selected

Parameters:

options (dict) – A dictionary of options. Keys are availiable options, values are what the function will return if that option is selected

Returns:

The value from the options dictionary that the user selected

Return type:

Object

Nice-prompts.

Generate nice looking prompts for your cli applications.

PyPI PyPI - Python Version Read the Docs

Install from PyPi:

$ pip3 install nice-prompts

Demo (select 1, select at least 2 with max 2, select any amount):

import nice_prompts

n = nice_prompts.NicePrompt()

print(n.selection({"I like pizza": "Good taste",
    "I respectfully disagree with the opinion of liking pizza": "Fair enough, good day",
    "I hate pizza": "Bad sport 👎"})) # Select one from the keys, return the value

print(n.multiselection({"I like pizza": "Good taste",
    "I respectfully disagree with the opinion of liking pizza": "Fair enough, good day",
    "I hate pizza": "Bad sport 👎"}, amount=2, required=2)) # Select multiple from the keys, return the values. You must select 2


print(n.multiselection({"I like pizza": "Good taste",
    "I respectfully disagree with the opinion of liking pizza": "Fair enough, good day",
    "I hate pizza": "Bad sport 👎"}, required=0))  # Select multiple from the keys, return the values. No max, can be left blank
Demo