aisk / pick

create curses based interactive selection list in the terminal
MIT License
729 stars 63 forks source link

Support for initial selection? #37

Closed hartwork closed 3 years ago

hartwork commented 4 years ago

Hi, thanks for sharing pick as software libre! :pray:

In my scenario I need to pre-select some options, primarily for multi-select mode. What I currently do at git-delete-merged-branches is this:

from pick import Picker

class _PickerWithPreselection(Picker):
    def __init__(self, options, initial_selection=None, **kwargs):
        super().__init__(options, **kwargs)
        if initial_selection is not None:
            self.all_selected = sorted(
                set(i for i in initial_selection if isinstance(i, int) and 0 <= i < len(options)))
            if self.all_selected and kwargs.get('default_index') is None:
                self.index = self.all_selected[0]

Is that something you'd want to integrate with pick?

Best, Sebastian

hartwork commented 4 years ago

Any thoughts?

wong2 commented 4 years ago

Yeah PR is welcomed

hartwork commented 3 years ago

Closing due to https://github.com/wong2/pick/pull/38#issuecomment-783307416