From 0a8b5cac6613ef25c0bf5832a822f76546d9ed70 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Tue, 4 Jul 2023 14:52:26 +0100 Subject: [PATCH] [ruby/reline] Refactor Reline::Core (https://github.com/ruby/reline/pull/561) * Use Reline::Core.encoding instead of directly referencing IOGate * Set input/output based on the IOGate's interface --- lib/reline.rb | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index ae98224653..7776bf4726 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -91,36 +91,36 @@ module Reline if val.nil? @completion_append_character = nil elsif val.size == 1 - @completion_append_character = val.encode(Reline::IOGate.encoding) + @completion_append_character = val.encode(encoding) elsif val.size > 1 - @completion_append_character = val[0].encode(Reline::IOGate.encoding) + @completion_append_character = val[0].encode(encoding) else @completion_append_character = nil end end def basic_word_break_characters=(v) - @basic_word_break_characters = v.encode(Reline::IOGate.encoding) + @basic_word_break_characters = v.encode(encoding) end def completer_word_break_characters=(v) - @completer_word_break_characters = v.encode(Reline::IOGate.encoding) + @completer_word_break_characters = v.encode(encoding) end def basic_quote_characters=(v) - @basic_quote_characters = v.encode(Reline::IOGate.encoding) + @basic_quote_characters = v.encode(encoding) end def completer_quote_characters=(v) - @completer_quote_characters = v.encode(Reline::IOGate.encoding) + @completer_quote_characters = v.encode(encoding) end def filename_quote_characters=(v) - @filename_quote_characters = v.encode(Reline::IOGate.encoding) + @filename_quote_characters = v.encode(encoding) end def special_prefixes=(v) - @special_prefixes = v.encode(Reline::IOGate.encoding) + @special_prefixes = v.encode(encoding) end def completion_case_fold=(v) @@ -181,20 +181,16 @@ module Reline def input=(val) raise TypeError unless val.respond_to?(:getc) or val.nil? - if val.respond_to?(:getc) - if defined?(Reline::ANSI) and Reline::IOGate == Reline::ANSI - Reline::ANSI.input = val - elsif Reline::IOGate == Reline::GeneralIO - Reline::GeneralIO.input = val - end + if val.respond_to?(:getc) && Reline::IOGate.respond_to?(:input=) + Reline::IOGate.input = val end end def output=(val) raise TypeError unless val.respond_to?(:write) or val.nil? @output = val - if defined?(Reline::ANSI) and Reline::IOGate == Reline::ANSI - Reline::ANSI.output = val + if Reline::IOGate.respond_to?(:output=) + Reline::IOGate.output = val end end @@ -313,7 +309,7 @@ module Reline otio = Reline::IOGate.prep may_req_ambiguous_char_width - line_editor.reset(prompt, encoding: Reline::IOGate.encoding) + line_editor.reset(prompt, encoding: encoding) if multiline line_editor.multiline_on if block_given? @@ -565,7 +561,7 @@ module Reline @core ||= Core.new { |core| core.config = Reline::Config.new core.key_stroke = Reline::KeyStroke.new(core.config) - core.line_editor = Reline::LineEditor.new(core.config, Reline::IOGate.encoding) + core.line_editor = Reline::LineEditor.new(core.config, core.encoding) core.basic_word_break_characters = " \t\n`><=;|&{(" core.completer_word_break_characters = " \t\n`><=;|&{("