piotrmurach / tty-prompt

A beautiful and powerful interactive command line prompt
https://ttytoolkit.org
MIT License
1.47k stars 136 forks source link

Preserve original choices order in multi_select prompt when selecting #146

Closed piotrmurach closed 4 years ago

piotrmurach commented 4 years ago

Adds SelectedChoices class to help keep the original choice order regardless of the selection order in multi_select prompt.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.06%) to 97.408% when pulling 58b1cf2703f6538e697a9e1ba489baab4ee697c6 on select-order into 3f9ef2ea859a47812bbca906161273d66a132f55 on master.

piotrmurach commented 4 years ago

@DanielVartanov I decided to try and see how this may be solved. So far I get quite optimistic results. Thanks to caching selected items size there is even a small speed improvement over the baseline. Please review when you have a minute.

DanielVartanov commented 4 years ago

Hey! Sorry it took me too long to reply, crazy days. This is amazing! :+1: I figured out why my initial benchark was different -- I've been pre-selecting thousands of choices (to populate @selected more) and then "clicking" one choice back and forth, apparently it did give the difference. BUT this solution beats everything in both benchmarks, I'm glad it's going to be merged

DanielVartanov commented 4 years ago

@piotrmurach sorry, can you please release the gem with this fix? I'm using tty-prompt for a script of guided deployment where this fix is the difference between uptime and downtime.

piotrmurach commented 4 years ago

@DanielVartanov Unfortunately, I cannot release the gem yet. I'm in the middle of adding :quiet option and need to finish the newest pastel version. This is a major release that I need to get 'right' as many things have been changed internally and many gems rely on (see changelog). Can you not patch the keyspace method with the sort solution for the time being? The release is nearly ready but I don't want to commit to a deadline. I will let you know once a new version gets released. Sorry, I know that's not the answer you expected but I hope you understand. I'm struggling to find time at the minute but will do my best to release soon.

DanielVartanov commented 4 years ago

@piotrmurach I see, no problem, I didn't realise it is a bigger deal than I initially thought :+1:

piotrmurach commented 4 years ago

@DanielVartanov There are many changes, including new conversions that don't raise errors but provide info to the user. I hope a better user experience. I'm currently following a hand-drawn chart with all the tty gems on it and updating/fixing them one by one. The tty-prompt and pastel are my sole focus at the minute as they're used by a few other gems. So I expect to release them soonish provided I make good progress and find the time.