awslabs / aws-shell

An integrated shell for working with the AWS CLI.
Apache License 2.0
7.19k stars 773 forks source link

Select Menu Implementation and Integration #132

Closed joguSD closed 8 years ago

joguSD commented 8 years ago

An implementation of a selection menu using prompt toolkit. This is very similar to the original prompt provided by prompt toolkit but has a few tweaks that are not possible through the parameters exposed by the library itself. Selecting an option from a set of options is a different enough use case that the following features were required: forcing the selection of one of the options, not allowing the editing of options once selected, and showing the prompt without any input from the user. Additionally, it allows me to modify the layout to begin adding a meta information window similar to the shell's docs.

@JordonPhillips @kyleknap @jamesls

JordonPhillips commented 8 years ago

Could we get some screenshots?

joguSD commented 8 years ago

Displays without user input, with no selection.

screen shot 2016-07-27 at 16 54 50

Upon making a selection it is highlighted and the selection will cycle.

screen shot 2016-07-27 at 16 55 16

The layout currently always displays the scroll bar, but this could be opened up to configuration.

screen shot 2016-07-27 at 16 56 52

Upon making a selection the menu is no longer displayed.

screen shot 2016-07-27 at 16 57 00

Visually it should be identical to the standard prompt from prompt_toolkit, and supports most of the same configuration as the args and kwargs are just forwarded along. There are a couple of configurations that the prompt shortcut helper function exposes that I have not included for simplicity.

Slightly more experimental and not being utilized currently is the meta information that would be displayed like this:

screen shot 2016-07-27 at 17 08 14

How exactly the meta information is rendered is something we need to discuss, but this type of interaction is required for an Info Select interaction.

JordonPhillips commented 8 years ago

Awesome job! No big issues, just a lot of wording and a few clarifications.

joguSD commented 8 years ago

I realized that there was a potential bug in the select menu when there are multiple options that are the same string. Previously I was using a dict to map options to their complete object, and the select menu prompt would simply return the string that was the selection so that the interaction could use it as a key and get the real object from the dict. However, this has conflicts if the string is the same for two options as they would return the same thing (one of the objects would get overwritten in the dict). I've refactored some things so that the options_meta is a parallel list to the list of options, and the select menu prompt will now return the tuple (selection, index) so that even in the case of duplicate options the correct resolution can be made. I also added an integration test to verify this functionality.

JordonPhillips commented 8 years ago
___________________________________________________________________
||     *                            *                    ((   *  ||
||        *                 *                *            ~      ||
||                ___.                          *          *     ||
||       *    ___.\__|.__.           *                           ||
||            \__|. .| \_|.                                      ||
||            . X|___|___| .                         *           ||
||          .__/_||____ ||__.            *                /\     ||
||  *     .  |/|____ |_\|_ |/ _                          /  \    ||
||        \ _/ |_X__\|_  |\||~,~{                       /    \   ||
||         \/\ |/|    |_ |/:|`X'{                   _ _/      \__||
||          \ \/ |___ |_\|_.|~~~                   /    . .. . ..||
||         _|X/\ |___\|_ :| |_.                  - .......... . .||
||         | __\_:____ |  ||o-|            ___/........ . . .. ..||
||         |/_-|-_|__ \|_ |/--|       ____/  . . .. . . .. ... . ||
|| ........:| -|- o-o\_:_\|o-/:....../...........................||
|| ._._._._._\=\====o==o==o=/:.._._._._._._._._._._._._._._._._._||
|| _._._._._._\_\ ._._._._.:._._._._._._._._._._._._._.P_._._._._||
|| ._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._||
||---------------------------------------------------------------||