aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-08-12 11:17:48 +0100
committergit <svn-admin@ruby-lang.org>2023-08-12 10:17:52 +0000
commit680835085df7695b18af40c7a8554f2d314b5de5 (patch)
tree0e5de8a5e22307773cb6f058e056e1d28ac8a864 /lib
parentd1b1e4a3ffc294b52c3934fdbce60807b9b708e7 (diff)
downloadruby-680835085df7695b18af40c7a8554f2d314b5de5.tar.gz
[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
Diffstat (limited to 'lib')
-rw-r--r--lib/irb/input-method.rb62
1 files 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