diff options
-rw-r--r-- | examples/menus.rb | 3 | ||||
-rw-r--r-- | lib/highline/menu.rb | 22 |
2 files changed, 19 insertions, 6 deletions
diff --git a/examples/menus.rb b/examples/menus.rb index ffa63bf..c925c07 100644 --- a/examples/menus.rb +++ b/examples/menus.rb @@ -26,6 +26,9 @@ choose do |menu| menu.choice :ruby do say("Good choice!") end menu.choices(:python, :perl) do say("Not from around here, are you?") end + + menu.default = :ruby + end say("\nThis is letter indexing...") diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb index 8dc9247..02d547a 100644 --- a/lib/highline/menu.rb +++ b/lib/highline/menu.rb @@ -516,23 +516,33 @@ class HighLine case @layout when :list %(<%= header ? "#{header}:\n" : '' %>) + - "<%= list( menu, #{@flow.inspect}, - #{@list_option.inspect} ) %>" + + parse_list + + show_default_if_any + "<%= prompt %>" when :one_line %(<%= header ? "#{header}: " : '' %>) + "<%= prompt %>" + - "(<%= list( menu, #{@flow.inspect}, - #{@list_option.inspect} ) %>)" + + "(" + parse_list + ")" + + show_default_if_any + "<%= prompt[/\s*$/] %>" when :menu_only - "<%= list( menu, #{@flow.inspect}, - #{@list_option.inspect} ) %><%= prompt %>" + parse_list + + show_default_if_any + + "<%= prompt %>" else @layout end end + def parse_list + "<%= list( menu, #{@flow.inspect}, + #{@list_option.inspect} ) %>" + end + + def show_default_if_any + return !@default.to_s.empty? ? "(#{@default}) " : "" + end + # # This method will update the intelligent responses to account for # Menu specific differences. Calls the superclass' (Question's) |