Skip to content

Commit

Permalink
Reline/ReadlineInputMethod should inherit StdioInputMethod (#671)
Browse files Browse the repository at this point in the history
They are both built on top of stdio and are basically extended version
of StdioInputMethod. They also share several attributes and methods with
StdioInputMethod.
  • Loading branch information
st0012 authored Aug 12, 2023
1 parent 4a6af7d commit c5f5abd
Showing 1 changed file with 6 additions and 56 deletions.
62 changes: 6 additions & 56 deletions lib/irb/input-method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def close
end

begin
class ReadlineInputMethod < InputMethod
class ReadlineInputMethod < StdioInputMethod
def self.initialize_readline
require "readline"
rescue LoadError
Expand All @@ -177,12 +177,9 @@ def initialize
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
Expand Down Expand Up @@ -214,28 +211,6 @@ def eof?
@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'
Expand All @@ -247,19 +222,16 @@ def inspect
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
Expand Down Expand Up @@ -421,28 +393,6 @@ def eof?
@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
Expand Down

0 comments on commit c5f5abd

Please sign in to comment.