module CF::Interactive
Public Instance Methods
ask(question, options = {})
click to toggle source
Calls superclass method
# File lib/cf/cli/interactive.rb, line 11 def ask(question, options = {}) if force? and options.key?(:default) options[:default] else super end end
handler(event, state)
click to toggle source
Calls superclass method
# File lib/cf/cli/interactive.rb, line 57 def handler(event, state) ans = state.answer exit if event == :eof if state.default? if event.is_a?(Array) and event[0] == :key # initial non-movement keypress clears default answer clear_input(state) else # wipe away any coloring redraw_input(state) end state.clear_default! if event != :up # tab with a default accepts it and moves to the end if event == :tab state.goto(ans.size) else super end else super end print "\n" if event == :enter end
input_state(options)
click to toggle source
# File lib/cf/cli/interactive.rb, line 25 def input_state(options) if options.key? :default answer = show_default(options) end CFState.new(options, answer) end
list_choices(choices, options = {})
click to toggle source
# File lib/cf/cli/interactive.rb, line 19 def list_choices(choices, options = {}) choices.each_with_index do |o, i| puts "#{c(i + 1, :number)}: #{show_choice(o, options)}" end end
prompt(question, options)
click to toggle source
# File lib/cf/cli/interactive.rb, line 46 def prompt(question, options) value = show_default(options) print "#{question}" print c("> ", :prompt) unless value.empty? print "#{d(value) + "\b" * value.size}" end end
show_default(options)
click to toggle source
# File lib/cf/cli/interactive.rb, line 33 def show_default(options) case options[:default] when true "y" when false "n" when nil "" else show_choice(options[:default], options) end end