pick an option in the terminal with a simple GUI
Project description
pick [![Build Status](https://travis-ci.org/wong2/pick.svg?branch=master)](https://travis-ci.org/wong2/pick) [![PyPI](https://img.shields.io/pypi/v/pick.svg)](https://pypi-hypernode.com/pypi/pick)
====
**pick** is a small python library to help you create curses based interactive selection
list in the terminal. See it in action:
![Demo](example/basic.gif?raw=true)
### Installation
$ pip install pick
### 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)
>>> print selected
**outputs**
>>> [('Java', 0), ('C++', 4)]
#### Options
* `options`: a list of options to choose from
* `title`: (optional) a title above options list
* `multi_select`: (optional), if set to True its possible to select multiple items by hitting SPACE
* `indicator`: (optional) custom the selection indicator, defaults to *
* `default_index`: (optional) set this if the default selected option is not the first one
#### Register custom handlers
sometimes you may need to register custom handlers to specific 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.
====
**pick** is a small python library to help you create curses based interactive selection
list in the terminal. See it in action:
![Demo](example/basic.gif?raw=true)
### Installation
$ pip install pick
### 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)
>>> print selected
**outputs**
>>> [('Java', 0), ('C++', 4)]
#### Options
* `options`: a list of options to choose from
* `title`: (optional) a title above options list
* `multi_select`: (optional), if set to True its possible to select multiple items by hitting SPACE
* `indicator`: (optional) custom the selection indicator, defaults to *
* `default_index`: (optional) set this if the default selected option is not the first one
#### Register custom handlers
sometimes you may need to register custom handlers to specific 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.
Project details
Release history Release notifications | RSS feed
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.2.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file pick-0.6.2.tar.gz
.
File metadata
- Download URL: pick-0.6.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13155348650102a8334e77938d7d8177e691f118dc032a107dce2c9747271609 |
|
MD5 | f87d317d9375ff7a6f3f18d83387d353 |
|
BLAKE2b-256 | dea10c074d6747d0d2d10aee26d6700a270968c136123f677d32096e8c40fc17 |
File details
Details for the file pick-0.6.2-py2.py3-none-any.whl
.
File metadata
- Download URL: pick-0.6.2-py2.py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b845b672f3dc7ea36c52540e6d6d86e3c7d6516137276e99037a93bb557f726 |
|
MD5 | 943253dfcedb5b5304311dfade84ad68 |
|
BLAKE2b-256 | 428a986d57d73872b1782568a907226fbf81165427270e259fcbbc2b7bed8ddb |