AlecAivazis / survey

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.
MIT License
4.07k stars 350 forks source link

Add a RemoveSelectAll and RemoveSelectNone config to multi-select #439

Closed ces131 closed 1 year ago

ces131 commented 1 year ago

Adds a config to prevent users from selecting all of the survey options and a config to remove the "select none/de-select all" option in multiselect. Using survey.WithRemoveSelectAll() will disable the ability for the right arrow key to select all of the options. It will also remove the instructions from the multi-select prompt. Similarly, survey.WithRemoveSelectNone() will disable not allow a user to select none/de-select all options and the instruction won't show up in the prompt.

Aurora Innovation has a patch with this work in their repo, and I figured I would make the change upstream. I filed a ticket quite awhile ago and finally got around to adding the change: https://github.com/AlecAivazis/survey/issues/393

Test Plan

Ran all of the tests. Added a new test that verifies the correct prompt and checks that using the right arrow key doesn't select all the options and using the left arrow key doesn't de-select all the options.

AlecAivazis commented 1 year ago

Thanks for putting this together @ces131! Should removing the select all also remove the select none behavior? Maybe we want a second option while we're here?

ces131 commented 1 year ago

Thanks for putting this together @ces131! Should removing the select all also remove the select none behavior? Maybe we want a second option while we're here?

If you'd like, I can add an additional option RemoveSelectNone while I'm here - for our use case I think we'd like to keep the "none" option even with the SelectAll removed. Sometimes our mulit-select question is "preloaded"/has a few options pre-selected so a quick way for the user to remove all of those is a nice to have

AlecAivazis commented 1 year ago

Yea i think we should just for completeness. thanks!

ces131 commented 1 year ago

Looks good! thanks for updating the docs (and the ping 😅 )

No problem at all! Thanks for the review 😄