All Projects → wong2 → Pick

wong2 / Pick

Licence: mit
create curses based interactive selection list in the terminal

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pick

Pulsemixer
CLI and curses mixer for PulseAudio
Stars: ✭ 441 (+19.19%)
Mutual labels:  cli, terminal, curses
Haxor News
Browse Hacker News like a haxor: A Hacker News command line interface (CLI).
Stars: ✭ 3,342 (+803.24%)
Mutual labels:  cli, terminal
Eureka
💡 CLI tool to input and store your ideas without leaving the terminal
Stars: ✭ 316 (-14.59%)
Mutual labels:  cli, terminal
Nord Dircolors
An arctic, north-bluish clean and elegant dircolors theme.
Stars: ✭ 328 (-11.35%)
Mutual labels:  cli, terminal
Termox
C++17 Terminal User Interface(TUI) Library.
Stars: ✭ 306 (-17.3%)
Mutual labels:  terminal, curses
Caporal.js
A full-featured framework for building command line applications (cli) with node.js
Stars: ✭ 3,279 (+786.22%)
Mutual labels:  cli, terminal
Tqdm
A Fast, Extensible Progress Bar for Python and CLI
Stars: ✭ 20,632 (+5476.22%)
Mutual labels:  cli, terminal
Spotui
Spotify in the terminal 💻🎶
Stars: ✭ 302 (-18.38%)
Mutual labels:  cli, terminal
Cmd2
cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python
Stars: ✭ 342 (-7.57%)
Mutual labels:  cli, terminal
Hues
Colored terminal text made easy for Python and happiness.
Stars: ✭ 345 (-6.76%)
Mutual labels:  cli, terminal
Libterm
iOS sandboxed terminal with Python, Lua and Clang
Stars: ✭ 348 (-5.95%)
Mutual labels:  cli, terminal
Stig
TUI and CLI for the BitTorrent client Transmission
Stars: ✭ 360 (-2.7%)
Mutual labels:  cli, terminal
Has
✅ checks presence of various command line tools and their versions on the path
Stars: ✭ 309 (-16.49%)
Mutual labels:  cli, terminal
Peaclock
A responsive and customizable clock, timer, and stopwatch for the terminal.
Stars: ✭ 314 (-15.14%)
Mutual labels:  cli, terminal
Pastel
A command-line tool to generate, analyze, convert and manipulate colors
Stars: ✭ 3,742 (+911.35%)
Mutual labels:  cli, terminal
Fd
A simple, fast and user-friendly alternative to 'find'
Stars: ✭ 19,851 (+5265.14%)
Mutual labels:  cli, terminal
Colorls
A Ruby gem that beautifies the terminal's ls command, with color and font-awesome icons. 🎉
Stars: ✭ 3,896 (+952.97%)
Mutual labels:  cli, terminal
Tmuxp
💻 tmux session manager. built on libtmux
Stars: ✭ 3,269 (+783.51%)
Mutual labels:  cli, terminal
Travis Watch
Stream live travis test results of the current commit to your terminal!
Stars: ✭ 294 (-20.54%)
Mutual labels:  cli, terminal
Stup
Daily notes in the terminal 🐧
Stars: ✭ 340 (-8.11%)
Mutual labels:  cli, terminal

pick

.. image:: https://travis-ci.org/wong2/pick.svg?branch=master :alt: Build Status :target: https://travis-ci.org/wong2/pick

.. image:: https://img.shields.io/pypi/v/pick.svg :alt: PyPI :target: https://pypi.python.org/pypi/pick

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

.. image:: example/basic.gif?raw=true :alt: Demo

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, multiselect=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
  • multiselect: (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)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].