groupick is a small python library based on wong2's pick which allows you to create a curses-based interactive selection in the terminal. With groupick you can assign options to groups.
$ pip install groupick
groupick comes with a simple api:
>>> from groupick import groupick
>>> instructions = "Assign languages to groups 'a', 'b' or '1'."
>>> options = ["Java", "JavaScript", "Python", "PHP", "C++", "Erlang", "Haskell"]
>>> groups:set = {"a", "b", 1}
>>> selected = groupick(options, groups, instructions, indicator="=>", default_index=2)
>>> print(f"Here is your assignment: {selected}")
output:
>>> {'1': [], 'a': [("JavaScript", 1)], 'b': []}
options
: a list of options to choose fromgroups
: a list of ints and/or characters symbolising groups (max-length per item is 1)instructions
: (optional) a title above options listindicator
: (optional) custom the selection indicator, defaults to*
default_index
: (optional) index of item where cursor starts at by defaulthandle_all
: (optional) define whether it is mandatory to assign all options to groups, defaults toFalse
screen
: (optional), if you are usinggroupick
within an existing curses application, pass your existingscreen
object. It is assumed this has initialised in the standard way (e.g. viacurses.wrapper()
, orcurses.noecho(); curses.cbreak(); screen.kepad(True)
)
wong2's pick: Original pick project, for selecting one or more options (no grouping)