InquirerPy icon indicating copy to clipboard operation
InquirerPy copied to clipboard

[Feature Request] Pin selected items on top when using fuzzy multi-select

Open shivams opened this issue 4 years ago • 5 comments

First of all, thanks a lot for this wonderful port. PyInquirer was using many old libraries and had become unusable. Your module comes as a life-saver!

Now, on to the issue (a feature request actually).

Let's say I have a list of 1000 items in my multi-select question. I would want my selected items to be shown (pinned) at the top. It helps to keep track of what has already been selected while doing the fuzzy searching.

shivams avatar Jan 29 '21 12:01 shivams

Hi @shivams,

Thanks for using the module. Sorry for the late response.

Regarding the feature request, you'd like to have selected items stick at the top no matter what word is being searched? So like if current choices are ["hello", "world", "foo", "boo"] and you have selected boo, you'd like boo to stick at the top even if the search field has asdfasfadsfas which yields zero available choices?

Please correct me if I misunderstand some of it, its a valid feature request and shouldn't be hard to implement. However, the concern would be what if out of 1000 choices, 100 choices (doesn't have to be this much), the terminal is usually not big enough to display other unselected choices, do you have any ideas or suggestions on the behaviour for this sort of situations? E.g. Terminal only has 20 lines to display, you have selected 21 choices, now there's probably no place to effectively display any non-selected choices.

Cheers, Kevin

kazhala avatar Feb 01 '21 21:02 kazhala

Hi @kazhala:

Yes. You understood it correctly. This is exactly what I have in mind. Thank you for explaining the feature request with an example.

The Concern

Your concern is valid. One solution could be to limit the visibility of the pinned options (i.e. only show up to, say, 5 items). But this wouldn't really solve the problem (since pinned items may easily go above a given limit).

Another (better) solution, if implementable, would be to have a separate section for pinned items. I am imagining a separate scrollable list of pinned items. In this case, we will then have 2 scrollable sections: one for selecting the items and one which contains selected items. Switching between these 2 sections could be done using TAB key. I have no idea if this is implementable or not.

shivams avatar Feb 01 '21 22:02 shivams

Hi @shivams,

I like your second solution, so could be like a split in the middle of all the choices. Left is the normal list of choices and the right split is only the selected choices. Perhaps an optional keybinding to toggle the split and provides keybinding to switch focus.

Should be alright to implement, I'll look into it when I get some time this weekend.

Cheers, Kevin

kazhala avatar Feb 01 '21 23:02 kazhala

I've got a more specific version of this ask basically can there be an option to remove this len() and just display self.selected_choices? And possibly hide the num_selected/num_choices count too.

if self._multiselect:
                display_message.append(
                    ("class:fuzzy_info", f" ({len(self.selected_choices)})")
                )

It could just stay on that line and go off to the right. Once you run out of space, ellipsis. Not perfect in all situations, but better than current behavior in some.

This would be useful in the case that you have many many options, but usually only select a few, less than 5.

Say we selected two options (['apple', 'bacon']), and then searched for 's'. It would be nice if instead of:

? Pick something:  
❯ s 2/13020 (2)
  sandwhich
  steak

it could show:

? Pick something:  
❯ s (['apple', 'bacon'])
  sandwhich
  steak

averypierce avatar Aug 16 '22 16:08 averypierce

f" ({list(map(lambda x: x.get('name','value'), self.selected_choices))})" basically does it, but I don't have a way to distribute it.

averypierce avatar Aug 16 '22 17:08 averypierce