@@ -77,19 +77,32 @@ def __init__(self, model, prompt_msg, prompter=select_prompt):
7777 super (SimpleSelect , self ).__init__ (model , prompt_msg )
7878 self ._prompter = prompter
7979
80- def execute (self , data ):
80+ def execute (self , data , show_meta = False ):
8181 if not isinstance (data , list ) or len (data ) < 1 :
8282 raise InteractionException ('SimpleSelect expects a non-empty list' )
8383 if self ._model .get ('Path' ) is not None :
8484 display_data = jmespath .search (self ._model ['Path' ], data )
85- result = self ._prompter ('%s ' % self .prompt , display_data )
85+ options_meta = data if show_meta else None
86+ result = self ._prompter ('%s ' % self .prompt , display_data ,
87+ options_meta = options_meta )
8688 (selected , index ) = result
8789 return data [index ]
8890 else :
8991 (selected , index ) = self ._prompter ('%s ' % self .prompt , data )
9092 return selected
9193
9294
95+ class InfoSelect (SimpleSelect ):
96+ """Display a list of options with meta information.
97+
98+ Small extension of :class:`SimpleSelect` that turns the show_meta flag on
99+ to display what the complete object looks like rendered as json in a pane
100+ below the prompt.
101+ """
102+ def execute (self , data ):
103+ return super (InfoSelect , self ).execute (data , show_meta = True )
104+
105+
93106class SimplePrompt (Interaction ):
94107 """Prompt the user to type in responses for each field.
95108
@@ -174,6 +187,7 @@ class InteractionLoader(object):
174187 Interaction objects can be instantiated from their corresponding str.
175188 """
176189 _INTERACTIONS = {
190+ 'InfoSelect' : InfoSelect ,
177191 'FuzzySelect' : FuzzySelect ,
178192 'SimpleSelect' : SimpleSelect ,
179193 'SimplePrompt' : SimplePrompt ,
0 commit comments