highline 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,6 @@ $terminal = HighLine.new
20
20
  # class for detailed explinations.
21
21
  #
22
22
  module Kernel
23
- extend Forwardable
24
- def_delegators :$terminal, :agree, :ask, :choose, :say
23
+ extend Forwardable
24
+ def_delegators :$terminal, :agree, :ask, :choose, :say
25
25
  end
data/lib/highline/menu.rb CHANGED
@@ -3,373 +3,371 @@
3
3
  # menu.rb
4
4
  #
5
5
  # Created by Gregory Thomas Brown on 2005-05-10.
6
- # Copyright 2005 smtose.org. All rights reserved.
6
+ # Copyright 2005. All rights reserved.
7
7
 
8
8
  require "highline/question"
9
9
 
10
10
  class HighLine
11
- #
12
- # Menu objects encapsulate all the details of a call to HighLine.choose().
13
- # Using the accessors and Menu.choice() and Menu.choices(), the block passed
14
- # to HighLine.choose() can detail all aspects of menu display and control.
15
- #
16
- class Menu < Question
17
- #
18
- # Create an instance of HighLine::Menu. All customization is done
19
- # through the passed block, which should call accessors and choice() and
20
- # choices() as needed to define the Menu. Note that Menus are also
21
- # Questions, so all that functionality is available to the block as
22
- # well.
23
- #
24
- def initialize( )
25
- #
26
- # Initialize Question objects with ignored values, we'll
27
- # adjust ours as needed.
28
- #
29
- super("Ignored", [ ], &nil) # avoiding passing the block along
30
-
31
- @items = [ ]
32
- @help = Hash.new("There's no help for that topic.")
11
+ #
12
+ # Menu objects encapsulate all the details of a call to HighLine.choose().
13
+ # Using the accessors and Menu.choice() and Menu.choices(), the block passed
14
+ # to HighLine.choose() can detail all aspects of menu display and control.
15
+ #
16
+ class Menu < Question
17
+ #
18
+ # Create an instance of HighLine::Menu. All customization is done
19
+ # through the passed block, which should call accessors and choice() and
20
+ # choices() as needed to define the Menu. Note that Menus are also
21
+ # Questions, so all that functionality is available to the block as
22
+ # well.
23
+ #
24
+ def initialize( )
25
+ #
26
+ # Initialize Question objects with ignored values, we'll
27
+ # adjust ours as needed.
28
+ #
29
+ super("Ignored", [ ], &nil) # avoiding passing the block along
30
+
31
+ @items = [ ]
32
+ @help = Hash.new("There's no help for that topic.")
33
33
 
34
- @index = :number
35
- @index_suffix = ". "
36
- @select_by = :index_or_name
37
- @flow = :rows
38
- @list_option = nil
39
- @header = nil
40
- @prompt = "? "
41
- @layout = :list
42
- @shell = false
43
- @nil_on_handled = false
44
-
45
- # Override Questions responses, we'll set our own.
46
- @responses = { }
47
- # Context for action code.
48
- @highline = nil
49
-
50
- yield self if block_given?
34
+ @index = :number
35
+ @index_suffix = ". "
36
+ @select_by = :index_or_name
37
+ @flow = :rows
38
+ @list_option = nil
39
+ @header = nil
40
+ @prompt = "? "
41
+ @layout = :list
42
+ @shell = false
43
+ @nil_on_handled = false
44
+
45
+ # Override Questions responses, we'll set our own.
46
+ @responses = { }
47
+ # Context for action code.
48
+ @highline = nil
49
+
50
+ yield self if block_given?
51
51
 
52
- init_help if @shell and not @help.empty?
53
- update_responses # rebuild responses based on our settings
54
- end
52
+ init_help if @shell and not @help.empty?
53
+ update_responses # rebuild responses based on our settings
54
+ end
55
55
 
56
- #
57
- # An _index_ to append to each menu item in display. See
58
- # Menu.index=() for details.
59
- #
60
- attr_reader :index
61
- #
62
- # The String placed between an _index_ and a menu item. Defaults to
63
- # ". ". Switches to " ", when _index_ is set to a String (like "-").
64
- #
65
- attr_accessor :index_suffix
66
- #
67
- # The _select_by_ attribute controls how the user is allowed to pick a
68
- # menu item. The available choices are:
69
- #
70
- # <tt>:index</tt>:: The user is allowed to type the numerical
71
- # or alphetical index for their selection.
72
- # <tt>:index_or_name</tt>:: Allows both methods from the
73
- # <tt>:index</tt> option and the
74
- # <tt>:name</tt> option.
75
- # <tt>:name</tt>:: Menu items are selected by typing a portion
76
- # of the item name that will be
77
- # auto-completed.
78
- #
79
- attr_accessor :select_by
80
- #
81
- # This attribute is passed directly on as the mode to HighLine.list() by
82
- # all the preset layouts. See that method for appropriate settings.
83
- #
84
- attr_accessor :flow
85
- #
86
- # This setting is passed on as the third parameter to HighLine.list()
87
- # by all the preset layouts. See that method for details of its
88
- # effects. Defaults to +nil+.
89
- #
90
- attr_accessor :list_option
91
- #
92
- # Used by all the preset layouts to display title and/or introductory
93
- # information, when set. Defaults to +nil+.
94
- #
95
- attr_accessor :header
96
- #
97
- # Used by all the preset layouts to ask the actual question to fetch a
98
- # menu selection from the user. Defaults to "? ".
99
- #
100
- attr_accessor :prompt
101
- #
102
- # An ERb _layout_ to use when displaying this Menu object. See
103
- # Menu.layout=() for details.
104
- #
105
- attr_reader :layout
106
- #
107
- # When set to +true+, responses are allowed to be an entire line of
108
- # input, including details beyond the command itself. Only the first
109
- # "word" of input will be matched against the menu choices, but both the
110
- # command selected and the rest of the line will be passed to provided
111
- # action blocks. Defaults to +false+.
112
- #
113
- attr_accessor :shell
114
- #
115
- # When +true+, any selected item handled by provided action code, will
116
- # return +nil+, instead of the results to the action code. This may
117
- # prove handy when dealing with mixed menus where only the names of
118
- # items without any code (and +nil+, of course) will be returned.
119
- # Defaults to +false+.
120
- #
121
- attr_accessor :nil_on_handled
122
-
123
- #
124
- # Adds _name_ to the list of available menu items. Menu items will be
125
- # displayed in the order they are added.
126
- #
127
- # An optional _action_ can be associated with this name and if provided,
128
- # it will be called if the item is selected. The result of the method
129
- # will be returned, unless _nil_on_handled_ is set (when you would get
130
- # +nil+ instead). In _shell_ mode, a provided block will be passed the
131
- # command chosen and any details that followed the command. Otherwise,
132
- # just the command is passed. The <tt>@highline</tt> variable is set to
133
- # the current HighLine context before the action code is called and can
134
- # thus be used for adding output and the like.
135
- #
136
- def choice( name, help = nil, &action )
137
- @items << [name, action]
138
-
139
- @help[name.to_s.downcase] = help unless help.nil?
140
- end
141
-
142
- #
143
- # A shortcut for multiple calls to the sister method choice(). <b>Be
144
- # warned:</b> An _action_ set here will apply to *all* provided
145
- # _names_. This is considered to be a feature, so you can easily
146
- # hand-off interface processing to a different chunk of code.
147
- #
148
- def choices( *names, &action )
149
- names.each { |n| choice(n, &action) }
150
- end
151
-
152
- #
153
- # Sets the indexing style for this Menu object. Indexes are appended to
154
- # menu items, when displayed in list form. The available settings are:
155
- #
156
- # <tt>:number</tt>:: Menu items will be indexed numerically, starting
157
- # with 1. This is the default method of indexing.
158
- # <tt>:letter</tt>:: Items will be indexed alphabetically, starting
159
- # with a.
160
- # <tt>:none</tt>:: No index will be appended to menu items.
161
- # <i>any String</i>:: Will be used as the literal _index_.
162
- #
163
- # Setting the _index_ to <tt>:none</tt> a literal String, also adjusts
164
- # _index_suffix_ to a single space and _select_by_ to <tt>:none</tt>.
165
- # Because of this, you should make a habit of setting the _index_ first.
166
- #
167
- def index=( style )
168
- @index = style
169
-
170
- # Default settings.
171
- if @index == :none or @index.is_a?(String)
172
- @index_suffix = " "
173
- @select_by = :name
174
- end
175
- end
176
-
177
- #
178
- # Initializes the help system by adding a <tt>:help</tt> choice, some
179
- # action code, and the default help listing.
180
- #
181
- def init_help( )
182
- return if @items.include?(:help)
183
-
184
- topics = @help.keys.sort
185
- help_help = @help.include?("help") ? @help["help"] :
186
- "This command will display helpful messages about " +
187
- "functionality, like this one. To see the help for " +
188
- "a specific topic enter:\n\thelp [TOPIC]\nTry asking " +
189
- "for help on any of the following:\n\n" +
190
- "<%= list(#{topics.inspect}, :columns_across) %>"
191
- choice(:help, help_help) do |command, topic|
192
- topic.strip!
193
- topic.downcase!
194
- if topic.empty?
195
- @highline.say(@help["help"])
196
- else
197
- @highline.say("= #{topic}\n\n#{@help[topic]}")
198
- end
199
- end
200
- end
201
-
202
- #
203
- # Used to set help for arbitrary topics. Use the topic <tt>"help"</tt>
204
- # to override the default message.
205
- #
206
- def help( topic, help )
207
- @help[topic] = help
208
- end
209
-
210
- #
211
- # Setting a _layout_ with this method also adjusts some other attributes
212
- # of the Menu object, to ideal defaults for the chosen _layout_. To
213
- # account for that, you probably want to set a _layout_ first in your
214
- # configuration block, if needed.
215
- #
216
- # Accepted settings for _layout_ are:
217
- #
218
- # <tt>:list</tt>:: The default _layout_. The _header_ if set
219
- # will appear at the top on its own line with
220
- # a trailing colon. Then the list of menu
221
- # items will follow. Finally, the _prompt_
222
- # will be used as the ask()-like question.
223
- # <tt>:one_line</tt>:: A shorter _layout_ that fits on one line.
224
- # The _header_ comes first followed by a
225
- # colon and spaces, then the _prompt_ with menu
226
- # items between trailing parenthesis.
227
- # <tt>:menu_only</tt>:: Just the menu items, followed up by a likely
228
- # short _prompt_.
229
- # <i>any ERb String</i>:: Will be taken as the literal _layout_. This
230
- # String can access <tt>@header</tt>,
231
- # <tt>@menu</tt> and <tt>@prompt</tt>, but is
232
- # otherwise evaluated in the typical HighLine
233
- # context, to provide access to utilities like
234
- # HighLine.list() primarily.
235
- #
236
- # If set to either <tt>:one_line</tt>, or <tt>:menu_only</tt>, _index_
237
- # will default to <tt>:none</tt> and _flow_ will default to
238
- # <tt>:inline</tt>.
239
- #
240
- def layout=( new_layout )
241
- @layout = new_layout
242
-
243
- # Default settings.
244
- case @layout
245
- when :one_line, :menu_only
246
- self.index = :none
247
- @flow = :inline
248
- end
249
- end
56
+ #
57
+ # An _index_ to append to each menu item in display. See
58
+ # Menu.index=() for details.
59
+ #
60
+ attr_reader :index
61
+ #
62
+ # The String placed between an _index_ and a menu item. Defaults to
63
+ # ". ". Switches to " ", when _index_ is set to a String (like "-").
64
+ #
65
+ attr_accessor :index_suffix
66
+ #
67
+ # The _select_by_ attribute controls how the user is allowed to pick a
68
+ # menu item. The available choices are:
69
+ #
70
+ # <tt>:index</tt>:: The user is allowed to type the numerical
71
+ # or alphetical index for their selection.
72
+ # <tt>:index_or_name</tt>:: Allows both methods from the
73
+ # <tt>:index</tt> option and the
74
+ # <tt>:name</tt> option.
75
+ # <tt>:name</tt>:: Menu items are selected by typing a portion
76
+ # of the item name that will be
77
+ # auto-completed.
78
+ #
79
+ attr_accessor :select_by
80
+ #
81
+ # This attribute is passed directly on as the mode to HighLine.list() by
82
+ # all the preset layouts. See that method for appropriate settings.
83
+ #
84
+ attr_accessor :flow
85
+ #
86
+ # This setting is passed on as the third parameter to HighLine.list()
87
+ # by all the preset layouts. See that method for details of its
88
+ # effects. Defaults to +nil+.
89
+ #
90
+ attr_accessor :list_option
91
+ #
92
+ # Used by all the preset layouts to display title and/or introductory
93
+ # information, when set. Defaults to +nil+.
94
+ #
95
+ attr_accessor :header
96
+ #
97
+ # Used by all the preset layouts to ask the actual question to fetch a
98
+ # menu selection from the user. Defaults to "? ".
99
+ #
100
+ attr_accessor :prompt
101
+ #
102
+ # An ERb _layout_ to use when displaying this Menu object. See
103
+ # Menu.layout=() for details.
104
+ #
105
+ attr_reader :layout
106
+ #
107
+ # When set to +true+, responses are allowed to be an entire line of
108
+ # input, including details beyond the command itself. Only the first
109
+ # "word" of input will be matched against the menu choices, but both the
110
+ # command selected and the rest of the line will be passed to provided
111
+ # action blocks. Defaults to +false+.
112
+ #
113
+ attr_accessor :shell
114
+ #
115
+ # When +true+, any selected item handled by provided action code, will
116
+ # return +nil+, instead of the results to the action code. This may
117
+ # prove handy when dealing with mixed menus where only the names of
118
+ # items without any code (and +nil+, of course) will be returned.
119
+ # Defaults to +false+.
120
+ #
121
+ attr_accessor :nil_on_handled
122
+
123
+ #
124
+ # Adds _name_ to the list of available menu items. Menu items will be
125
+ # displayed in the order they are added.
126
+ #
127
+ # An optional _action_ can be associated with this name and if provided,
128
+ # it will be called if the item is selected. The result of the method
129
+ # will be returned, unless _nil_on_handled_ is set (when you would get
130
+ # +nil+ instead). In _shell_ mode, a provided block will be passed the
131
+ # command chosen and any details that followed the command. Otherwise,
132
+ # just the command is passed. The <tt>@highline</tt> variable is set to
133
+ # the current HighLine context before the action code is called and can
134
+ # thus be used for adding output and the like.
135
+ #
136
+ def choice( name, help = nil, &action )
137
+ @items << [name, action]
138
+
139
+ @help[name.to_s.downcase] = help unless help.nil?
140
+ end
141
+
142
+ #
143
+ # A shortcut for multiple calls to the sister method choice(). <b>Be
144
+ # warned:</b> An _action_ set here will apply to *all* provided
145
+ # _names_. This is considered to be a feature, so you can easily
146
+ # hand-off interface processing to a different chunk of code.
147
+ #
148
+ def choices( *names, &action )
149
+ names.each { |n| choice(n, &action) }
150
+ end
151
+
152
+ #
153
+ # Sets the indexing style for this Menu object. Indexes are appended to
154
+ # menu items, when displayed in list form. The available settings are:
155
+ #
156
+ # <tt>:number</tt>:: Menu items will be indexed numerically, starting
157
+ # with 1. This is the default method of indexing.
158
+ # <tt>:letter</tt>:: Items will be indexed alphabetically, starting
159
+ # with a.
160
+ # <tt>:none</tt>:: No index will be appended to menu items.
161
+ # <i>any String</i>:: Will be used as the literal _index_.
162
+ #
163
+ # Setting the _index_ to <tt>:none</tt> a literal String, also adjusts
164
+ # _index_suffix_ to a single space and _select_by_ to <tt>:none</tt>.
165
+ # Because of this, you should make a habit of setting the _index_ first.
166
+ #
167
+ def index=( style )
168
+ @index = style
169
+
170
+ # Default settings.
171
+ if @index == :none or @index.is_a?(String)
172
+ @index_suffix = " "
173
+ @select_by = :name
174
+ end
175
+ end
176
+
177
+ #
178
+ # Initializes the help system by adding a <tt>:help</tt> choice, some
179
+ # action code, and the default help listing.
180
+ #
181
+ def init_help( )
182
+ return if @items.include?(:help)
183
+
184
+ topics = @help.keys.sort
185
+ help_help = @help.include?("help") ? @help["help"] :
186
+ "This command will display helpful messages about " +
187
+ "functionality, like this one. To see the help for " +
188
+ "a specific topic enter:\n\thelp [TOPIC]\nTry asking " +
189
+ "for help on any of the following:\n\n" +
190
+ "<%= list(#{topics.inspect}, :columns_across) %>"
191
+ choice(:help, help_help) do |command, topic|
192
+ topic.strip!
193
+ topic.downcase!
194
+ if topic.empty?
195
+ @highline.say(@help["help"])
196
+ else
197
+ @highline.say("= #{topic}\n\n#{@help[topic]}")
198
+ end
199
+ end
200
+ end
201
+
202
+ #
203
+ # Used to set help for arbitrary topics. Use the topic <tt>"help"</tt>
204
+ # to override the default message.
205
+ #
206
+ def help( topic, help )
207
+ @help[topic] = help
208
+ end
209
+
210
+ #
211
+ # Setting a _layout_ with this method also adjusts some other attributes
212
+ # of the Menu object, to ideal defaults for the chosen _layout_. To
213
+ # account for that, you probably want to set a _layout_ first in your
214
+ # configuration block, if needed.
215
+ #
216
+ # Accepted settings for _layout_ are:
217
+ #
218
+ # <tt>:list</tt>:: The default _layout_. The _header_ if set
219
+ # will appear at the top on its own line with
220
+ # a trailing colon. Then the list of menu
221
+ # items will follow. Finally, the _prompt_
222
+ # will be used as the ask()-like question.
223
+ # <tt>:one_line</tt>:: A shorter _layout_ that fits on one line.
224
+ # The _header_ comes first followed by a
225
+ # colon and spaces, then the _prompt_ with menu
226
+ # items between trailing parenthesis.
227
+ # <tt>:menu_only</tt>:: Just the menu items, followed up by a likely
228
+ # short _prompt_.
229
+ # <i>any ERb String</i>:: Will be taken as the literal _layout_. This
230
+ # String can access <tt>@header</tt>,
231
+ # <tt>@menu</tt> and <tt>@prompt</tt>, but is
232
+ # otherwise evaluated in the typical HighLine
233
+ # context, to provide access to utilities like
234
+ # HighLine.list() primarily.
235
+ #
236
+ # If set to either <tt>:one_line</tt>, or <tt>:menu_only</tt>, _index_
237
+ # will default to <tt>:none</tt> and _flow_ will default to
238
+ # <tt>:inline</tt>.
239
+ #
240
+ def layout=( new_layout )
241
+ @layout = new_layout
242
+
243
+ # Default settings.
244
+ case @layout
245
+ when :one_line, :menu_only
246
+ self.index = :none
247
+ @flow = :inline
248
+ end
249
+ end
250
250
 
251
- #
252
- # This method returns all possible options for auto-completion, based
253
- # on the settings of _index_ and _select_by_.
254
- #
255
- def options( )
256
- by_index = if @index == :letter
257
- l_index = "`"
258
- @items.map { "#{l_index.succ!}" }
259
- else
260
- (1 .. @items.size).collect { |s| String(s) }
261
- end
262
- by_name = @items.collect { |c| c.first }
251
+ #
252
+ # This method returns all possible options for auto-completion, based
253
+ # on the settings of _index_ and _select_by_.
254
+ #
255
+ def options( )
256
+ by_index = if @index == :letter
257
+ l_index = "`"
258
+ @items.map { "#{l_index.succ!}" }
259
+ else
260
+ (1 .. @items.size).collect { |s| String(s) }
261
+ end
262
+ by_name = @items.collect { |c| c.first }
263
263
 
264
- case @select_by
265
- when :index then
266
- by_index
267
- when :name
268
- by_name
269
- else
270
- by_index + by_name
271
- end
272
- end
264
+ case @select_by
265
+ when :index then
266
+ by_index
267
+ when :name
268
+ by_name
269
+ else
270
+ by_index + by_name
271
+ end
272
+ end
273
273
 
274
- #
275
- # This method processes the auto-completed user selection, based on the
276
- # rules for this Menu object. If an action was provided for the
277
- # selection, it will be executed as described in Menu.choice().
278
- #
279
- def select( highline_context, selection, details = nil )
280
- # Find the selected action.
281
- name, action = if selection =~ /^\d+$/
282
- @items[selection.to_i - 1]
283
- else
284
- l_index = "`"
285
- index = @items.map { "#{l_index.succ!}" }.index(selection)
286
- @items.find { |c| c.first == selection } or @items[index]
287
- end
288
-
289
- # Run or return it.
290
- if not @nil_on_handled and not action.nil?
291
- @highline = highline_context
292
- if @shell
293
- action.call(name, details)
294
- else
295
- action.call(name)
296
- end
297
- elsif action.nil?
298
- name
299
- else
300
- nil
301
- end
302
- end
303
-
304
- #
305
- # Allows Menu objects to pass as Arrays, for use with HighLine.list().
306
- # This method returns all menu items to be displayed, complete with
307
- # indexes.
308
- #
309
- def to_ary( )
310
- case @index
311
- when :number
312
- @items.map do |c|
313
- "#{@items.index(c) + 1}#{@index_suffix}#{c.first}"
314
- end
315
- when :letter
316
- l_index = "`"
317
- @items.map { |c| "#{l_index.succ!}#{@index_suffix}#{c.first}" }
318
- when :none
319
- @items.map { |c| "#{c.first}" }
320
- else
321
- @items.map { |c| "#{index}#{@index_suffix}#{c.first}" }
322
- end
323
- end
324
-
325
- #
326
- # Allows Menu to behave as a String, just like Question. Returns the
327
- # _layout_ to be rendered, which is used by HighLine.say().
328
- #
329
- def to_str( )
330
- case @layout
331
- when :list
332
- '<%= if @header.nil? then '' else "#{@header}:\n" end %>' +
333
- "<%= list( @menu, #{@flow.inspect},
334
- #{@list_option.inspect} ) %>" +
335
- "<%= @prompt %>"
336
- when :one_line
337
- '<%= if @header.nil? then '' else "#{@header}: " end %>' +
338
- "<%= @prompt %>" +
339
- "(<%= list( @menu, #{@flow.inspect},
340
- #{@list_option.inspect} ) %>)" +
341
- "<%= @prompt[/\s*$/] %>"
342
- when :menu_only
343
- "<%= list( @menu, #{@flow.inspect},
344
- #{@list_option.inspect} ) %><%= @prompt %>"
345
- else
346
- @layout
347
- end
348
- end
274
+ #
275
+ # This method processes the auto-completed user selection, based on the
276
+ # rules for this Menu object. If an action was provided for the
277
+ # selection, it will be executed as described in Menu.choice().
278
+ #
279
+ def select( highline_context, selection, details = nil )
280
+ # Find the selected action.
281
+ name, action = if selection =~ /^\d+$/
282
+ @items[selection.to_i - 1]
283
+ else
284
+ l_index = "`"
285
+ index = @items.map { "#{l_index.succ!}" }.index(selection)
286
+ @items.find { |c| c.first == selection } or @items[index]
287
+ end
288
+
289
+ # Run or return it.
290
+ if not @nil_on_handled and not action.nil?
291
+ @highline = highline_context
292
+ if @shell
293
+ action.call(name, details)
294
+ else
295
+ action.call(name)
296
+ end
297
+ elsif action.nil?
298
+ name
299
+ else
300
+ nil
301
+ end
302
+ end
303
+
304
+ #
305
+ # Allows Menu objects to pass as Arrays, for use with HighLine.list().
306
+ # This method returns all menu items to be displayed, complete with
307
+ # indexes.
308
+ #
309
+ def to_ary( )
310
+ case @index
311
+ when :number
312
+ @items.map { |c| "#{@items.index(c) + 1}#{@index_suffix}#{c.first}" }
313
+ when :letter
314
+ l_index = "`"
315
+ @items.map { |c| "#{l_index.succ!}#{@index_suffix}#{c.first}" }
316
+ when :none
317
+ @items.map { |c| "#{c.first}" }
318
+ else
319
+ @items.map { |c| "#{index}#{@index_suffix}#{c.first}" }
320
+ end
321
+ end
322
+
323
+ #
324
+ # Allows Menu to behave as a String, just like Question. Returns the
325
+ # _layout_ to be rendered, which is used by HighLine.say().
326
+ #
327
+ def to_str( )
328
+ case @layout
329
+ when :list
330
+ '<%= if @header.nil? then '' else "#{@header}:\n" end %>' +
331
+ "<%= list( @menu, #{@flow.inspect},
332
+ #{@list_option.inspect} ) %>" +
333
+ "<%= @prompt %>"
334
+ when :one_line
335
+ '<%= if @header.nil? then '' else "#{@header}: " end %>' +
336
+ "<%= @prompt %>" +
337
+ "(<%= list( @menu, #{@flow.inspect},
338
+ #{@list_option.inspect} ) %>)" +
339
+ "<%= @prompt[/\s*$/] %>"
340
+ when :menu_only
341
+ "<%= list( @menu, #{@flow.inspect},
342
+ #{@list_option.inspect} ) %><%= @prompt %>"
343
+ else
344
+ @layout
345
+ end
346
+ end
349
347
 
350
- #
351
- # This method will update the intelligent responses to account for
352
- # Menu specific differences. This overrides the work done by
353
- # Question.build_responses().
354
- #
355
- def update_responses( )
356
- append_default unless default.nil?
357
- @responses = { :ambiguous_completion =>
358
- "Ambiguous choice. " +
359
- "Please choose one of #{options.inspect}.",
360
- :ask_on_error =>
361
- "? ",
362
- :invalid_type =>
363
- "You must enter a valid #{options}.",
364
- :no_completion =>
365
- "You must choose one of " +
366
- "#{options.inspect}.",
367
- :not_in_range =>
368
- "Your answer isn't within the expected range " +
369
- "(#{expected_range}).",
370
- :not_valid =>
371
- "Your answer isn't valid (must match " +
372
- "#{@validate.inspect})." }.merge(@responses)
373
- end
374
- end
348
+ #
349
+ # This method will update the intelligent responses to account for
350
+ # Menu specific differences. This overrides the work done by
351
+ # Question.build_responses().
352
+ #
353
+ def update_responses( )
354
+ append_default unless default.nil?
355
+ @responses = { :ambiguous_completion =>
356
+ "Ambiguous choice. " +
357
+ "Please choose one of #{options.inspect}.",
358
+ :ask_on_error =>
359
+ "? ",
360
+ :invalid_type =>
361
+ "You must enter a valid #{options}.",
362
+ :no_completion =>
363
+ "You must choose one of " +
364
+ "#{options.inspect}.",
365
+ :not_in_range =>
366
+ "Your answer isn't within the expected range " +
367
+ "(#{expected_range}).",
368
+ :not_valid =>
369
+ "Your answer isn't valid (must match " +
370
+ "#{@validate.inspect})." }.merge(@responses)
371
+ end
372
+ end
375
373
  end