Skip to main content

pick an option in the terminal with a simple GUI

Project description

Build Status PyPI

pick is a small python library to help you create curses based interactive selection list in the terminal. See it in action:

Demo

Installation

$ pip install pick

Note for Windows: run pip install windows-curses to enable curses module support.

Usage

pick comes with a simple api:

>>> from pick import pick

>>> title = 'Please choose your favorite programming language: '
>>> options = ['Java', 'JavaScript', 'Python', 'PHP', 'C++', 'Erlang', 'Haskell']
>>> option, index = pick(options, title)
>>> print(option)
>>> print(index)

outputs:

>>> C++
>>> 4

pick multiselect example:

>>> from pick import pick

>>> title = 'Please choose your favorite programming language (press SPACE to mark, ENTER to continue): '
>>> options = ['Java', 'JavaScript', 'Python', 'PHP', 'C++', 'Erlang', 'Haskell']
>>> selected = pick(options, title, multi_select=True, min_selection_count=1)
>>> print(selected)

outputs:

>>> [('Java', 0), ('C++', 4)]

Options

  • options: a list of options to choose from

  • title: (optional) a title above options list

  • indicator: (optional) custom the selection indicator, defaults to *

  • default_index: (optional) set this if the default selected option is not the first one

  • multi_select: (optional), if set to True its possible to select multiple items by hitting SPACE

  • min_selection_count: (optional) for multi select feature to dictate a minimum of selected items before continuing

  • options_map_func: (optional) a mapping function to pass each option through before displaying

Register custom handlers

Sometimes you may need to register custom handlers for specific keyboard keys, you can use the register_custom_handler API:

>>> from pick import Picker
>>> title, options = 'Title', ['Option1', 'Option2']
>>> picker = Picker(options, title)
>>> def go_back(picker):
...     return None, -1
>>> picker.register_custom_handler(ord('h'),  go_back)
>>> option, index = picker.start()
  • the custom handler will be called with the picker instance as it’s parameter.

  • the custom handler should either return a two element tuple, or None.

  • if None is returned, the picker would continue to run, otherwise the picker will stop and return the tuple.

Options Map Function

If your options are not in a format that you want displayed (such as a dictionary), you can pass in a mapping function which each option will be run through. The return value of the function will be displayed.

  • the selected option returned will be the original value and not the displayed return result from the options_map_func function.

pick options map function example:

>>> from pick import pick

>>> title = 'Please choose an option: '
>>> options = [{'label': 'option1'}, {'label': 'option2'}, {'label': 'option3'}]

>>> def get_label(option): return option.get('label')

>>> selected = pick(options, title, indicator='*', options_map_func=get_label)
>>> print(selected)

displays:

Please choose an option:

* option1
  option2
  option3

outputs:

>>> ({ 'label': 'option1' }, 0)

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

pick-0.6.5.tar.gz (5.3 kB view details)

Uploaded Source

Built Distributions

pick-0.6.5-py3.7.egg (7.5 kB view details)

Uploaded Source

pick-0.6.5-py2.py3-none-any.whl (5.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pick-0.6.5.tar.gz.

File metadata

  • Download URL: pick-0.6.5.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.4.2 requests/2.13.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.21.0 CPython/2.7.15

File hashes

Hashes for pick-0.6.5.tar.gz
Algorithm Hash digest
SHA256 94f23f247b2e048136532349e8e9d4860d2ea8b4d049eaf92525943d391705d8
MD5 22a647ccea730e3e613faa87b133fc15
BLAKE2b-256 de5ba636235c2ecf0076b5ee9e978d691ef20e9769319cac0cfd5c79abfb73d4

See more details on using hashes here.

File details

Details for the file pick-0.6.5-py3.7.egg.

File metadata

  • Download URL: pick-0.6.5-py3.7.egg
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.4.2 requests/2.13.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.21.0 CPython/2.7.15

File hashes

Hashes for pick-0.6.5-py3.7.egg
Algorithm Hash digest
SHA256 b9b9a98f01866cb107456c377213575e3ab1d445661579dabc99812ef2439052
MD5 a359a0d350954ed6981579329b446911
BLAKE2b-256 fdf2157e071d15afc5593d20f397986cb5e16f8492344566212fa79989b30157

See more details on using hashes here.

File details

Details for the file pick-0.6.5-py2.py3-none-any.whl.

File metadata

  • Download URL: pick-0.6.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.4.2 requests/2.13.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.21.0 CPython/2.7.15

File hashes

Hashes for pick-0.6.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 32fa0dd4bb6103eccb3e5ae3cb737fabf991e3d89dea4018a3d7111c94541845
MD5 103d8d8b776635497dd8b7576c8504af
BLAKE2b-256 dcaa0677c337a80d3e4bf71c71c09c4e8d9d00729acf37cd0ac8faf096a38cb3

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