class ThorRepl::Looper
Public Class Methods
new(thor_commands_class:, readline_class: Readline, welcome_message: true, prompt: ">")
click to toggle source
# File lib/thor_repl/looper.rb, line 5 def initialize(thor_commands_class:, readline_class: Readline, welcome_message: true, prompt: ">") @welcome_message = welcome_message @readline_class = readline_class @thor_commands_class = thor_commands_class @prompt = prompt end
Public Instance Methods
run()
click to toggle source
# File lib/thor_repl/looper.rb, line 12 def run Signal.trap("INT", method(:sigint_handler)) puts "Welcome to interactive mode. Use 'help' to list available commands" if @welcome_message repl(-> () { @readline_class.readline(@prompt, true) }) do |input| args = CSV.parse_line(input, col_sep: "\s") @thor_commands_class.start(args) end end
Private Instance Methods
repl(input_proc) { |input| ... }
click to toggle source
# File lib/thor_repl/looper.rb, line 29 def repl(input_proc) while (input = input_proc.call) case input when /^exit!?/ break when /^$/ Readline::HISTORY.pop end yield(input) if block_given? end end
sigint_handler(*args)
click to toggle source
# File lib/thor_repl/looper.rb, line 25 def sigint_handler(*args) print "^C\n#{@prompt}" end