Skip to main content

Interactive list selection and multiselect for POSIX terminals (non-curses)

Project description

python-listpicker

Interactive list selection for POSIX terminals.

pip install listpicker

Python 3.10+

Features

  • Single and multiple selection from a sequence of strings
  • Interactive substring filtering
  • Paging for long lists
  • Common navigation keybindings (vi, emacs, arrow keys, Home/End, etc)
  • Direct terminal manipulation with CSI commands (i.e. no curses)
  • Draw to main screen buffer without clearing the screen
  • Proper truncation of long lines with SGR color sequences
  • Redraw on terminal resize (SIGWINCH)
  • Help menu and multiselect confirmation prompt
  • Preselected options in multiselect prompts

Screenshots

timezones helpmenu filtering multiselect multiselect-confirmation

Examples

Basic usage

import listpicker

pizza_styles = ("Thin crust", "Stuffed crust", "Deep dish")
style = listpicker.pick("Choose pizza style:", pizza_styles)

# User can abort input, so handle the case where "pick()" returns "None"
if style is None:
    style = pizza_styles[0]

pizza_toppings = ("Pepperoni", "Sausage", "Mushroom", "Pineapple")
toppings = listpicker.pick_multiple("Choose toppings:", pizza_toppings)

Typical usage with dictionary

import dataclasses

import listpicker


@dataclasses.dataclass
class Book:
    isbn: str
    title: str
    authors: list[str]
    publication_year: int


books = [
    Book(
        "0201038013",
        "The Art of Computer Programming, Volume 1: Fundamental Algorithms",
        ["Knuth, Donald"],
        1968,
    ),
    Book(
        "0262010771",
        "Structure and Interpretation of Computer Programs",
        ["Harold Abelson", "Gerald Jay Sussman", "Julie Sussman"],
        1984,
    ),
    Book(
        "032163537X",
        "Elements of Programming",
        ["Stepanov, Alexander A.", "McJones, Paul"],
        2009,
    ),
]

options = {f"{b.title} ({b.publication_year})": b for b in books}
choice = listpicker.pick("Pick a book:", list(options.keys()))

# Pick a book:
#   (filter with f, submit with Enter, F1 for keybindings)
# > 1. The Art of Computer Programming, Volume 1: Fundamental Algorithms (1968)
#   2. Structure and Interpretation of Computer Programs (1984)
#   3. Elements of Programming (2009)

if choice:
    book = options[choice]

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

listpicker-0.3.2.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

listpicker-0.3.2-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file listpicker-0.3.2.tar.gz.

File metadata

  • Download URL: listpicker-0.3.2.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for listpicker-0.3.2.tar.gz
Algorithm Hash digest
SHA256 fcd5dccd1d1ce65cbad686f572307a80ad6a03906bb1c160df535dc4dcaf33a7
MD5 4825e7d2c327228c4e07544738d47de8
BLAKE2b-256 b019bd7db0d1c426a69b393db9735ed9c4e8ae2b45319ca54322f15d906b3b7f

See more details on using hashes here.

File details

Details for the file listpicker-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: listpicker-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for listpicker-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c481114412a3216113537999e21962e4c43dcd88175832c43f82e5a108b5480d
MD5 3836bd5215b4f2e5a3f0d28a9b5556fa
BLAKE2b-256 ed6bfe93db6c1fcd8010bfca9ec78397a696e4af7d9585e4391fd17d4c887641

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page