summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederico <fred.rbittencourt@gmail.com>2016-07-11 00:40:45 -0300
committerFrederico <fred.rbittencourt@gmail.com>2016-07-11 00:40:45 -0300
commitd789f437659d8942f272f92b8374c767963db4c4 (patch)
treeba1225990853739981ecfd82970eb802cd3b89a5
parent855cc18733a9953ea028456b14186c5a29fa70e0 (diff)
downloadhighline-d789f437659d8942f272f92b8374c767963db4c4.tar.gz
show default option for menus
-rw-r--r--examples/menus.rb3
-rw-r--r--lib/highline/menu.rb22
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)