@@ -77,19 +77,32 @@ def __init__(self, model, prompt_msg, prompter=select_prompt):
77
77
super (SimpleSelect , self ).__init__ (model , prompt_msg )
78
78
self ._prompter = prompter
79
79
80
- def execute (self , data ):
80
+ def execute (self , data , show_meta = False ):
81
81
if not isinstance (data , list ) or len (data ) < 1 :
82
82
raise InteractionException ('SimpleSelect expects a non-empty list' )
83
83
if self ._model .get ('Path' ) is not None :
84
84
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 )
86
88
(selected , index ) = result
87
89
return data [index ]
88
90
else :
89
91
(selected , index ) = self ._prompter ('%s ' % self .prompt , data )
90
92
return selected
91
93
92
94
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
+
93
106
class SimplePrompt (Interaction ):
94
107
"""Prompt the user to type in responses for each field.
95
108
@@ -174,6 +187,7 @@ class InteractionLoader(object):
174
187
Interaction objects can be instantiated from their corresponding str.
175
188
"""
176
189
_INTERACTIONS = {
190
+ 'InfoSelect' : InfoSelect ,
177
191
'FuzzySelect' : FuzzySelect ,
178
192
'SimpleSelect' : SimpleSelect ,
179
193
'SimplePrompt' : SimplePrompt ,
0 commit comments