[ruby/irb] Reline/ReadlineInputMethod should inherit

StdioInputMethod
(https://github.com/ruby/irb/pull/671)

They are both built on top of stdio and are basically extended version
of StdioInputMethod. They also share several attributes and methods with
StdioInputMethod.

https://github.com/ruby/irb/commit/c5f5abdbde
This commit is contained in:
Stan Lo 2023-08-12 11:17:48 +01:00 committed by git
parent d1b1e4a3ff
commit 680835085d

View File

@ -160,7 +160,7 @@ module IRB
end end
begin begin
class ReadlineInputMethod < InputMethod class ReadlineInputMethod < StdioInputMethod
def self.initialize_readline def self.initialize_readline
require "readline" require "readline"
rescue LoadError rescue LoadError
@ -177,12 +177,9 @@ module IRB
IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false) IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
end end
@line_no = 0 super
@line = []
@eof = false
@stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-") @eof = false
@stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
if Readline.respond_to?("basic_word_break_characters=") if Readline.respond_to?("basic_word_break_characters=")
Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
@ -214,28 +211,6 @@ module IRB
@eof @eof
end end
# Whether this input method is still readable when there is no more data to
# read.
#
# See IO#eof for more information.
def readable_after_eof?
true
end
# Returns the current line number for #io.
#
# #line counts the number of times #gets is called.
#
# See IO#lineno for more information.
def line(line_no)
@line[line_no]
end
# The external encoding for standard input.
def encoding
@stdin.external_encoding
end
# 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'
@ -247,19 +222,16 @@ module IRB
end end
end end
class RelineInputMethod < InputMethod class RelineInputMethod < StdioInputMethod
HISTORY = Reline::HISTORY HISTORY = Reline::HISTORY
include HistorySavingAbility include HistorySavingAbility
# Creates a new input method object using Reline # Creates a new input method object using Reline
def initialize def initialize
IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false) IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
@line_no = 0 super
@line = []
@eof = false
@stdin = ::IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-") @eof = false
@stdout = ::IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
Reline.completion_append_character = nil Reline.completion_append_character = nil
@ -421,28 +393,6 @@ module IRB
@eof @eof
end end
# Whether this input method is still readable when there is no more data to
# read.
#
# See IO#eof for more information.
def readable_after_eof?
true
end
# Returns the current line number for #io.
#
# #line counts the number of times #gets is called.
#
# See IO#lineno for more information.
def line(line_no)
@line[line_no]
end
# The external encoding for standard input.
def encoding
@stdin.external_encoding
end
# For debug message # For debug message
def inspect def inspect
config = Reline::Config.new config = Reline::Config.new