From 680835085df7695b18af40c7a8554f2d314b5de5 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 12 Aug 2023 11:17:48 +0100 Subject: [PATCH] [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 --- lib/irb/input-method.rb | 62 ++++------------------------------------- 1 file changed, 6 insertions(+), 56 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index 245b935668..b574a3fe1f 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -160,7 +160,7 @@ module IRB end begin - class ReadlineInputMethod < InputMethod + class ReadlineInputMethod < StdioInputMethod def self.initialize_readline require "readline" rescue LoadError @@ -177,12 +177,9 @@ module IRB IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false) end - @line_no = 0 - @line = [] - @eof = false + super - @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-") - @stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-") + @eof = false if Readline.respond_to?("basic_word_break_characters=") Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS @@ -214,28 +211,6 @@ module IRB @eof 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 def inspect readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline' @@ -247,19 +222,16 @@ module IRB end end - class RelineInputMethod < InputMethod + class RelineInputMethod < StdioInputMethod HISTORY = Reline::HISTORY include HistorySavingAbility # Creates a new input method object using Reline def initialize IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false) - @line_no = 0 - @line = [] - @eof = false + super - @stdin = ::IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-") - @stdout = ::IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-") + @eof = false Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS Reline.completion_append_character = nil @@ -421,28 +393,6 @@ module IRB @eof 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 def inspect config = Reline::Config.new