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)
====
**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)
#### 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
#### 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)
#### 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
#### 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.1.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file pick-0.6.1.tar.gz
.
File metadata
- Download URL: pick-0.6.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b94a088f77c5fd8e4d29e56bd0fc8dd32b655267d6a3687e06995c623986f03 |
|
MD5 | 13a3e4632c27c41bfc09e20528643d6e |
|
BLAKE2b-256 | dd7cabb170c9237551fef22c4a63e92aafb4c51487e360597352d1cfd4364438 |
File details
Details for the file pick-0.6.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pick-0.6.1-py2.py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e45d91b81f479625a9a4a9d1b7e2a042a389fb5c1eee5b378e07f5cface17f9 |
|
MD5 | eacc010e793c9cec441818bd26e42c24 |
|
BLAKE2b-256 | bedfbddef6a86ed180c17ca8c78d17b949038569f6c53ff607caae4a57780580 |