Skip to content

Commit

Permalink
Refactor Reline::Core (#561)
Browse files Browse the repository at this point in the history
* Use Reline::Core.encoding instead of directly referencing IOGate

* Set input/output based on the IOGate's interface
  • Loading branch information
st0012 authored Jul 4, 2023
1 parent 7958678 commit 45acc2f
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,36 @@ def completion_append_character=(val)
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)
Expand Down Expand Up @@ -181,20 +181,16 @@ def dialog_proc(name_sym)

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

Expand Down Expand Up @@ -313,7 +309,7 @@ def readline(prompt = '', add_hist = false)
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?
Expand Down Expand Up @@ -565,7 +561,7 @@ def self.core
@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`><=;|&{("
Expand Down

0 comments on commit 45acc2f

Please sign in to comment.