diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index 260d9a1cb..f7f0c80ae 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -175,10 +175,15 @@ def close class ReadlineInputMethod < StdioInputMethod class << self def initialize_readline - require "readline" - rescue LoadError - else - include ::Readline + return if defined?(self::Readline) + + begin + require 'readline' + const_set(:Readline, ::Readline) + rescue LoadError + const_set(:Readline, ::Reline) + end + const_set(:HISTORY, self::Readline::HISTORY) end end @@ -216,8 +221,8 @@ def completion_info def gets Readline.input = @stdin Readline.output = @stdout - if l = readline(@prompt, false) - HISTORY.push(l) if !l.empty? + if l = Readline.readline(@prompt, false) + Readline::HISTORY.push(l) if !l.empty? @line[@line_no += 1] = l + "\n" else @eof = true @@ -239,7 +244,7 @@ def prompting? # For debug message def inspect - readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline' + readline_impl = Readline == ::Reline ? 'Reline' : 'ext/readline' str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}" inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc') str += " and #{inputrc_path}" if File.exist?(inputrc_path) diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 0171bb0ec..77b680d91 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -1,6 +1,5 @@ # frozen_string_literal: false require 'irb' -require 'readline' require "tempfile" require_relative "helper" @@ -8,6 +7,13 @@ return if RUBY_PLATFORM.match?(/solaris|mswin|mingw/i) module TestIRB + begin + require 'readline' + Readline = ::Readline + rescue LoadError + Readline = ::Reline + end + class HistoryTest < TestCase def setup @conf_backup = IRB.conf.dup