1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/irb] Get rid of loading readline unnecessarily

420e7d2270
This commit is contained in:
Nobuyoshi Nakada 2020-08-12 11:21:36 +09:00 committed by aycabta
parent d32229e338
commit 6aa786b8a3
2 changed files with 9 additions and 11 deletions

View file

@ -7,7 +7,6 @@
# From Original Idea of shugo@ruby-lang.org # From Original Idea of shugo@ruby-lang.org
# #
require "readline"
autoload :RDoc, "rdoc" autoload :RDoc, "rdoc"
module IRB module IRB

View file

@ -143,11 +143,17 @@ module IRB
end end
begin begin
require "readline"
class ReadlineInputMethod < InputMethod class ReadlineInputMethod < InputMethod
include Readline def self.initialize_readline
require "readline"
rescue LoadError
else
include ::Readline
end
# Creates a new input method object using Readline # Creates a new input method object using Readline
def initialize def initialize
self.class.initialize_readline
if Readline.respond_to?(:encoding_system_needs) if Readline.respond_to?(:encoding_system_needs)
IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false) IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
end end
@ -212,12 +218,6 @@ module IRB
@stdin.external_encoding @stdin.external_encoding
end end
if Readline.respond_to?("basic_word_break_characters=")
Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
end
Readline.completion_append_character = nil
Readline.completion_proc = IRB::InputCompletor::CompletionProc
# For debug message # For debug message
def inspect def inspect
readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline' readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
@ -227,7 +227,6 @@ module IRB
str str
end end
end end
rescue LoadError
end end
class ReidlineInputMethod < InputMethod class ReidlineInputMethod < InputMethod
@ -251,7 +250,7 @@ module IRB
Reline.completion_proc = IRB::InputCompletor::CompletionProc Reline.completion_proc = IRB::InputCompletor::CompletionProc
Reline.output_modifier_proc = Reline.output_modifier_proc =
if IRB.conf[:USE_COLORIZE] if IRB.conf[:USE_COLORIZE]
proc do |output, complete:| proc do |output, complete: |
next unless IRB::Color.colorable? next unless IRB::Color.colorable?
IRB::Color.colorize_code(output, complete: complete) IRB::Color.colorize_code(output, complete: complete)
end end