Code Monkey home page Code Monkey logo

pzp's Introduction

pzp

Pure-python fzf-inspired element picker

Build Status PyPI version PyPI Downloads Code style: black Known Vulnerabilities Documentation

Requirements

  • Python 3.6+

Install

pip install pzp

Usage

from pzp import pzp
pzp(['a', 'b', 'c'])

Layout

The finder by default starts in fullscreen mode. You can make it start below the cursor with fullscreen=False option. Also, with the height argument you can limit the window height.

pzp(candidates=range(0, 1000), fullscreen=False, height=20)

asciicast

You can choose between the following layout using the layout option.

  • default Display from the bottom of the screen
  • reverse Display from the top of the screen
  • reverse-list Display from the top of the screen, prompt at the bottom

Search syntax

The finder starts in "extended-search mode" where you can type in multiple search terms delimited by spaces. e.g. ^music .mp3$ sbtrkt !fire

Token Match type Description
t1 t2 tokens-match Items that include t1 and t2
'star wars line-match (not-splitted) Items that include star wars
^music prefix-exact-match Items that start with music
.py$ suffix-exact-match Items that end with .py
!fire inverse-exact-match Items that do not include fire
!^music inverse-prefix-exact-match Items that do not start with music
!.py$ inverse-suffix-exact-match Items that do not end with .py

Key/Event Bindings

keys_binding argument allows you to bind one or more keys to one action. You can use it to customize key bindings or implementing custom behaviors.

try:
    item = pzp(
        candidates=candidates,
        keys_binding={
            "custom-action": ["ctrl-o"],
            "exclamation": ["!"]
        },
    )
    print(item)
except CustomAction as action:
    print(action.action)
    print(action.selected_item)

Available Keys

Key Synonyms type
space
tab
btab shift-tab
enter
esc
insert
del
bspace bs
up
down
left
right
home
end
pgdn page-down
pgup page-up
f1 - f12
ctrl-/
ctrl-\
ctrl-]
ctrl-^
ctrl-a - ctrl-z
any single character

Available Actions

A key can be bound to one of following actions or to a custom action.

Action* Default binding
accept enter
abort ctrl-c ctrl-g ctrl-q esc
beginning-of-line ctrl-a home
backward-char ctrl-b left
forward-char ctrl-f right
end-of-line ctrl-e end
backward-delete-char ctrl-h bspace
delete-char del
up ctrl-k ctrl-p up
down ctrl-j ctrl-n down
page-down pgdn
page-up pgup
ignore

Lazy Mode

lazy argument allows you to enable the lazy mode. If the Lazy mode is enabled, starts the finder only if the candidates are more than one. If there is only one match returns the only match, if there is no match returns None.

Licence

MIT

Links

pzp's People

Contributors

andreax79 avatar snyk-bot avatar

Stargazers

West Rynes avatar Sid Mitra avatar John Taylor avatar Rahuλ Dé avatar David McClosky avatar D. Bohdan avatar alaska avatar Andrew Johnson avatar Karim Vergnes avatar  avatar

Watchers

 avatar Kostas Georgiou avatar  avatar

pzp's Issues

info_style = InfoStyle.HIDDEN causes graphical glitch with reverse layout

If I show a Picker with info_style = InfoStyle.HIDDEN, fullscreen = False, layout = 'reverse', selecting or typing an option causes the entire widget to be redrawn one line above its original place, eventually overwriting my terminal history.

Footage:

Capture.video.du.2023-03-01.10-28-35.webm

Scrolling incorrect with wrapped long lines

An advantage that pzp has before fzf, IMO, is that it supports candidate lines too long to fit on the screen. pzp wraps them, while fzf cuts them off. I prefer pzp's behavior: I can truncate long lines to screen width if I want to.

There seems to be a scrolling bug related to this, though. Scrolling works incorrectly when there is line wrapping and too many lines in total to fit on the screen. It seems that scrolling does not take wrapped lines into account.

Here is a video demo from my phone, where the issue is easier to notice because of portrait mode.

pzp.mp4

Code for the demo:

#! /usr/bin/env python3

from pzp import pzp

items = [x * 32 for x in ("baz ", "foo ", "qux ", "baz ")]

print(pzp(candidates=items))

Suggestion: allow answers not in match

This would be useful for open-ended prompts, where an answer that isn't in the initial suggestion set can be entered.

That, or adding a secondary selection set which is only shown when you start typing or run out of matches, to emphasize the semantic difference between suggested and possible choices

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.