[Question] Adding search to custom widgets

Open
#1,145 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Start by comparing the custom ListView based on FormattedTextControl with the existing BufferControl search path. Read the default key bindings, prompt_toolkit.search module, and is_searching filters to understand the current coupling. Done would mean a documented, maintainable way to add search or filtering to custom widgets without duplicating the existing search logic.

Written by the indexing model from the issue text.

Description

Hi,

I am a new user of prompt_toolkit and so far like it. I am using it display and explore data from different APIs on the commandline. One such API is a Work/Task scheduling systems and I need to make information available for ~1000 subtasks at once.

To do this I wrote a widget ListView, which is based on a FormattedTextControl. This was really easy (and I consider how easy it was a major selling point for prompt_toolkit). However I struggle to find a good way to add search/filtering to it.

As far as I know the buildin search functionality is hardwired to BufferControl and even has isinstance checks in place. It's quite intrusive as well in the sense that from default key_bindings, to the prompt_toolkit.search module and the is_searching filters there is a lot that taps into it.

Do you have any suggestions on how to proceed? My current plan of action would be to just duplicate a lot of the logic into the 'ListView'-Widget. Are there any lessons learned from implementing the current search functionality?

I'd be grateful for any advice. Thank you! :-)

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prompt-toolkit/python-prompt-toolkit

All issues in prompt-toolkit/python-prompt-toolkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.