Module: Rutaci::Interaction
- Defined in:
- lib/rutaci/interaction.rb
Overview
writes info from a source into the files it is a command executor, so it has tp provide an initializer which takes the options and a method ‘run’ which takes an array of filenames
Class Method Summary collapse
-
.lineedit(promt, default_value, completion_strings = []) ⇒ Object
use GNU readline for the interactive input.
- .print_lineedit_help ⇒ Object
Class Method Details
.lineedit(promt, default_value, completion_strings = []) ⇒ Object
use GNU readline for the interactive input
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rutaci/interaction.rb', line 31 def self.lineedit(promt, default_value, completion_strings = []) # FIXME: display the default value and don't wait for the user to press TAB # it seems that this requires hacking the readline module add_to_history = true Readline.completion_proc = Proc.new do |current_line| if current_line.empty? # if we haven't typed anything, the completion is the default value candidates = [default_value] else # completion: look which completion string starts with what we've typed # TODO: don't search for the whole current_line, but also substrings. # example: current_file = "some foob" and completion_strings = ["foobar"] candidates = completion_strings.select {|str| str.index(current_line) == 0} end candidates end Readline.completion_append_character = "" # per default a space will be append begin value = Readline.readline promt, add_to_history rescue Interrupt puts # just to have the linebreak value = default_value end return value end |
.print_lineedit_help ⇒ Object
25 26 27 28 |
# File 'lib/rutaci/interaction.rb', line 25 def self.print_lineedit_help puts "Use <TAB> on an empty line will insert the default value, else completion is done" puts "Use <Ctrl-C> to discard your changes and use the default value" end |