lib/cliprompt.rb in cliprompt-0.0.3 vs lib/cliprompt.rb in cliprompt-0.0.4
- old
+ new
@@ -8,17 +8,30 @@
module_function
MSG_MANDATORY_TEXT = "Sorry you need to fill that information."
MSG_YES_OR_NO = "You need to answer by yes, no, y, n, 1 or 0."
MSG_CHOSE_IN_LIST = "You need to chose between the available options."
+ MSG_CHOSE_A_NUMBER = "Choose a number:"
def ask(question, *options)
if options[0].class == Optionset
opts = options[0]
else
opts = Optionset.new *options
end
- output.print "#{question} #{opts.display} "
+ if opts.aslist
+ output.puts "#{question}"
+ opts.choices.each_with_index do |choice, i|
+ if opts.default == choice
+ output.printf "> %-3s %s\n", i, choice
+ else
+ output.printf " %-3s %s\n", i, choice
+ end
+ end
+ output.print "#{MSG_CHOSE_A_NUMBER} "
+ else
+ output.print "#{question} #{opts.display} "
+ end
answer = input.gets.chomp
output.flush
opts.validate(question, answer)
end