lib/commando/io_handler.rb in tcollier-commando-1.0.0 vs lib/commando/io_handler.rb in tcollier-commando-2.0.0
- old
+ new
@@ -3,23 +3,23 @@
require_relative 'quit_exception'
module Commando
# Handle the prompt/input for the command line interface
class IOHandler
- def initialize(output:)
- @output = output
+ def initialize(config:)
+ @config = config
configure_readline
load_history
end
def readline
- line = Readline.readline(Commando.config.prompt, true)
+ line = Readline.readline(config.prompt, true)
if line.nil?
# When the user presses <CMD>+D, this comes through as nil. In that
# case we want to exit
- output.puts
+ config.output.puts
raise QuitException
elsif line.strip == ''
# If the user just hit enter without typing a command, remove that line
# from history.
Readline::HISTORY.pop
@@ -30,16 +30,16 @@
end
end
private
- attr_reader :output
+ attr_reader :config
def configure_readline
- Readline.output = output
+ Readline.output = config.output
Readline.completion_proc =
- proc { |s| Commando.config.commands.grep(/^#{Regexp.escape(s)}/) }
+ proc { |s| config.commands.grep(/^#{Regexp.escape(s)}/) }
end
def load_history
if history_file && File.exists?(history_file)
File.readlines(history_file).each do |line|
@@ -51,10 +51,10 @@
def save_history(line)
File.open(history_file, 'a') { |f| f.puts(line) } if history_file
end
def history_file
- Commando.config.history_file
+ config.history_file
end
end
private_constant :IOHandler
end