From 7ceae3668e6f7bdc31aaf16d34bea05c30052b09 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Wed, 5 Jul 2023 16:58:09 +0100 Subject: [PATCH] Store IO gate in `Config` and avoid referencing the `Reline::IOGate` directly IO gate is a component that's widely used in Reline. However, it's not supposed to be assigned right when `Reline` is loaded, which has been causing problems described in https://github.com/ruby/reline/issues/559 And the need to lazily assign it when `readline`/`readmultiline` being called means it should not be a constant but an attribute of either `Core` or `Config`. Since it's widely used in `LineEditor`, I think making it an attribute of `Config` is better than `Core`. Note: - The goal is to drop the `Reline::IOGate` constant completely. But I want to avoid making breaking change here as it's supposed to be a refactoring. --- lib/reline.rb | 62 ++++++------ lib/reline/config.rb | 6 +- lib/reline/line_editor.rb | 111 +++++++++++----------- test/reline/test_ansi_with_terminfo.rb | 2 +- test/reline/test_ansi_without_terminfo.rb | 2 +- test/reline/test_config.rb | 6 +- test/reline/test_key_actor_emacs.rb | 2 +- test/reline/test_key_actor_vi.rb | 2 +- test/reline/test_key_stroke.rb | 8 +- test/reline/test_line_editor.rb | 4 +- test/reline/test_macro.rb | 2 +- test/reline/test_string_processing.rb | 2 +- 12 files changed, 108 insertions(+), 101 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index 7776bf4726..00ae3792d4 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -76,15 +76,19 @@ class Core :autocompletion= def initialize - self.output = STDOUT @dialog_proc_list = {} yield self + self.output = STDOUT @completion_quote_character = nil @bracketed_paste_finished = false end + def io_gate + @config.io_gate + end + def encoding - Reline::IOGate.encoding + io_gate.encoding end def completion_append_character=(val) @@ -181,16 +185,16 @@ def dialog_proc(name_sym) def input=(val) raise TypeError unless val.respond_to?(:getc) or val.nil? - if val.respond_to?(:getc) && Reline::IOGate.respond_to?(:input=) - Reline::IOGate.input = val + if val.respond_to?(:getc) && io_gate.respond_to?(:input=) + io_gate.input = val end end def output=(val) raise TypeError unless val.respond_to?(:write) or val.nil? @output = val - if Reline::IOGate.respond_to?(:output=) - Reline::IOGate.output = val + if io_gate.respond_to?(:output=) + io_gate.output = val end end @@ -213,7 +217,7 @@ def emacs_editing_mode? end def get_screen_size - Reline::IOGate.get_screen_size + io_gate.get_screen_size end Reline::DEFAULT_DIALOG_PROC_AUTOCOMPLETE = ->() { @@ -266,7 +270,7 @@ def get_screen_size Reline::DEFAULT_DIALOG_CONTEXT = Array.new def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination) - Reline::IOGate.with_raw_input do + io_gate.with_raw_input do unless confirm_multiline_termination raise ArgumentError.new('#readmultiline needs block to confirm multiline termination') end @@ -298,7 +302,7 @@ def readline(prompt = '', add_hist = false) private def inner_readline(prompt, add_hist, multiline, &confirm_multiline_termination) if ENV['RELINE_STDERR_TTY'] - if Reline::IOGate.win? + if io_gate.win? $stderr = File.open(ENV['RELINE_STDERR_TTY'], 'a') else $stderr.reopen(ENV['RELINE_STDERR_TTY'], 'w') @@ -306,7 +310,7 @@ def readline(prompt = '', add_hist = false) $stderr.sync = true $stderr.puts "Reline is used by #{Process.pid}" end - otio = Reline::IOGate.prep + otio = io_gate.prep may_req_ambiguous_char_width line_editor.reset(prompt, encoding: encoding) @@ -333,7 +337,7 @@ def readline(prompt = '', add_hist = false) unless config.test_mode config.read config.reset_default_key_bindings - Reline::IOGate.set_default_key_bindings(config) + io_gate.set_default_key_bindings(config) end line_editor.rerender @@ -342,9 +346,9 @@ def readline(prompt = '', add_hist = false) line_editor.set_signal_handlers prev_pasting_state = false loop do - prev_pasting_state = Reline::IOGate.in_pasting? + prev_pasting_state = io_gate.in_pasting? read_io(config.keyseq_timeout) { |inputs| - line_editor.set_pasting_state(Reline::IOGate.in_pasting?) + line_editor.set_pasting_state(io_gate.in_pasting?) inputs.each { |c| line_editor.input_key(c) line_editor.rerender @@ -354,29 +358,29 @@ def readline(prompt = '', add_hist = false) @bracketed_paste_finished = false end } - if prev_pasting_state == true and not Reline::IOGate.in_pasting? and not line_editor.finished? + if prev_pasting_state == true and not io_gate.in_pasting? and not line_editor.finished? line_editor.set_pasting_state(false) prev_pasting_state = false line_editor.rerender_all end break if line_editor.finished? end - Reline::IOGate.move_cursor_column(0) + io_gate.move_cursor_column(0) rescue Errno::EIO # Maybe the I/O has been closed. rescue StandardError => e line_editor.finalize - Reline::IOGate.deprep(otio) + io_gate.deprep(otio) raise e rescue Exception # Including Interrupt line_editor.finalize - Reline::IOGate.deprep(otio) + io_gate.deprep(otio) raise end line_editor.finalize - Reline::IOGate.deprep(otio) + io_gate.deprep(otio) end # GNU Readline waits for "keyseq-timeout" milliseconds to see if the ESC @@ -391,7 +395,7 @@ def readline(prompt = '', add_hist = false) private def read_io(keyseq_timeout, &block) buffer = [] loop do - c = Reline::IOGate.getc + c = io_gate.getc if c == -1 result = :unmatched @bracketed_paste_finished = true @@ -431,7 +435,7 @@ def readline(prompt = '', add_hist = false) begin succ_c = nil Timeout.timeout(keyseq_timeout / 1000.0) { - succ_c = Reline::IOGate.getc + succ_c = io_gate.getc } rescue Timeout::Error # cancel matching only when first byte block.([Reline::Key.new(c, c, false)]) @@ -446,7 +450,7 @@ def readline(prompt = '', add_hist = false) end return :break when :matching - Reline::IOGate.ungetc(succ_c) + io_gate.ungetc(succ_c) return :next when :matched buffer << succ_c @@ -463,7 +467,7 @@ def readline(prompt = '', add_hist = false) begin escaped_c = nil Timeout.timeout(keyseq_timeout / 1000.0) { - escaped_c = Reline::IOGate.getc + escaped_c = io_gate.getc } rescue Timeout::Error # independent ESC block.([Reline::Key.new(c, c, false)]) @@ -486,19 +490,19 @@ def ambiguous_width end private def may_req_ambiguous_char_width - @ambiguous_width = 2 if Reline::IOGate == Reline::GeneralIO or !STDOUT.tty? + @ambiguous_width = 2 if io_gate == Reline::GeneralIO or !STDOUT.tty? return if defined? @ambiguous_width - Reline::IOGate.move_cursor_column(0) + io_gate.move_cursor_column(0) begin output.write "\u{25bd}" rescue Encoding::UndefinedConversionError # LANG=C @ambiguous_width = 1 else - @ambiguous_width = Reline::IOGate.cursor_pos.x + @ambiguous_width = io_gate.cursor_pos.x end - Reline::IOGate.move_cursor_column(0) - Reline::IOGate.erase_after_cursor + io_gate.move_cursor_column(0) + io_gate.erase_after_cursor end end @@ -559,7 +563,7 @@ def self.encoding_system_needs def self.core @core ||= Core.new { |core| - core.config = Reline::Config.new + core.config = Reline::Config.new(Reline::IOGate) core.key_stroke = Reline::KeyStroke.new(core.config) core.line_editor = Reline::LineEditor.new(core.config, core.encoding) @@ -574,7 +578,7 @@ def self.core end def self.ungetc(c) - Reline::IOGate.ungetc(c) + io_gate.ungetc(c) end def self.line_editor diff --git a/lib/reline/config.rb b/lib/reline/config.rb index 87726393a6..46f862443f 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -46,8 +46,9 @@ class InvalidInputrc < RuntimeError end attr_accessor :autocompletion + attr_accessor :io_gate - def initialize + def initialize(io_gate) @additional_key_bindings = {} # from inputrc @additional_key_bindings[:emacs] = {} @additional_key_bindings[:vi_insert] = {} @@ -70,7 +71,8 @@ def initialize @keyseq_timeout = 500 @test_mode = false @autocompletion = false - @convert_meta = true if seven_bit_encoding?(Reline::IOGate.encoding) + @io_gate = io_gate + @convert_meta = true if seven_bit_encoding?(@io_gate.encoding) end def reset diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 36375eee81..485452ac13 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -56,6 +56,7 @@ module CompletionState def initialize(config, encoding) @config = config + @io_gate = config.io_gate @completion_append_character = '' reset_variables(encoding: encoding) end @@ -148,11 +149,11 @@ def simplified_rendering? end def reset(prompt = '', encoding:) - @rest_height = (Reline::IOGate.get_screen_size.first - 1) - Reline::IOGate.cursor_pos.y - @screen_size = Reline::IOGate.get_screen_size + @rest_height = (@io_gate.get_screen_size.first - 1) - @io_gate.cursor_pos.y + @screen_size = @io_gate.get_screen_size @screen_height = @screen_size.first reset_variables(prompt, encoding: encoding) - Reline::IOGate.set_winch_handler do + @io_gate.set_winch_handler do @resized = true end if ENV.key?('RELINE_ALT_SCROLLBAR') @@ -160,7 +161,7 @@ def reset(prompt = '', encoding:) @upper_half_block = "''" @lower_half_block = '..' @block_elem_width = 2 - elsif Reline::IOGate.win? + elsif @io_gate.win? @full_block = '█' @upper_half_block = '▀' @lower_half_block = '▄' @@ -181,9 +182,9 @@ def reset(prompt = '', encoding:) def resize return unless @resized @resized = false - @rest_height = (Reline::IOGate.get_screen_size.first - 1) - Reline::IOGate.cursor_pos.y + @rest_height = (@io_gate.get_screen_size.first - 1) - @io_gate.cursor_pos.y old_screen_size = @screen_size - @screen_size = Reline::IOGate.get_screen_size + @screen_size = @io_gate.get_screen_size @screen_height = @screen_size.first if old_screen_size.last < @screen_size.last # columns increase @rerender_all = true @@ -212,7 +213,7 @@ def resize end calculate_nearest_cursor @started_from = calculate_height_by_width(prompt_width + @cursor) - 1 - Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @io_gate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max) @rerender_all = true end @@ -226,7 +227,7 @@ def set_signal_handlers else move_cursor_down(@highest_in_all - @line_index - 1) end - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) scroll_down(1) case @old_trap when 'DEFAULT', 'SYSTEM_DEFAULT' @@ -343,18 +344,18 @@ def multiline_off private def scroll_down(val) if val <= @rest_height - Reline::IOGate.move_cursor_down(val) + @io_gate.move_cursor_down(val) @rest_height -= val else - Reline::IOGate.move_cursor_down(@rest_height) - Reline::IOGate.scroll_down(val - @rest_height) + @io_gate.move_cursor_down(@rest_height) + @io_gate.scroll_down(val - @rest_height) @rest_height = 0 end end private def move_cursor_up(val) if val > 0 - Reline::IOGate.move_cursor_up(val) + @io_gate.move_cursor_up(val) @rest_height += val elsif val < 0 move_cursor_down(-val) @@ -363,7 +364,7 @@ def multiline_off private def move_cursor_down(val) if val > 0 - Reline::IOGate.move_cursor_down(val) + @io_gate.move_cursor_down(val) @rest_height -= val @rest_height = 0 if @rest_height < 0 elsif val < 0 @@ -438,14 +439,14 @@ def rerender end if @is_multiline and finished? and @scroll_partial_screen # Re-output all code higher than the screen when finished. - Reline::IOGate.move_cursor_up(@first_line_started_from + @started_from - @scroll_partial_screen) - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_up(@first_line_started_from + @started_from - @scroll_partial_screen) + @io_gate.move_cursor_column(0) @scroll_partial_screen = nil new_lines = whole_lines prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines) modify_lines(new_lines).each_with_index do |line, index| @output.write "#{prompt_list ? prompt_list[index] : prompt}#{line}\r\n" - Reline::IOGate.erase_after_cursor + @io_gate.erase_after_cursor end @output.flush clear_dialog(cursor_column) @@ -485,8 +486,8 @@ def rerender render_partial(prompt, prompt_width, line, @first_line_started_from) move_cursor_down(@highest_in_all - (@first_line_started_from + @highest_in_this - 1) - 1) scroll_down(1) - Reline::IOGate.move_cursor_column(0) - Reline::IOGate.erase_after_cursor + @io_gate.move_cursor_column(0) + @io_gate.erase_after_cursor else if not rendered and not @in_pasting line = modify_lines(whole_lines)[@line_index] @@ -502,8 +503,8 @@ def rerender render_partial(prompt, prompt_width, line, 0) if finished? scroll_down(1) - Reline::IOGate.move_cursor_column(0) - Reline::IOGate.erase_after_cursor + @io_gate.move_cursor_column(0) + @io_gate.erase_after_cursor end end end @@ -716,7 +717,7 @@ def add_dialog_proc(name, p, context = nil) end # Clear and rerender all dialogs line by line - Reline::IOGate.hide_cursor + @io_gate.hide_cursor ymin, ymax = (ranges_to_restore.keys + new_dialog_ranges.keys).minmax scroll_partial_screen = @scroll_partial_screen || 0 screen_y_range = scroll_partial_screen..(scroll_partial_screen + @screen_height - 1) @@ -740,24 +741,24 @@ def add_dialog_proc(name, p, context = nil) col = range.begin width = range.end - range.begin s = padding_space_with_escape_sequences(Reline::Unicode.take_range(line, col, width), width) - Reline::IOGate.move_cursor_column(col) + @io_gate.move_cursor_column(col) @output.write "\e[0m#{s}\e[0m" end max_column = [calculate_width(line, true), new_x_ranges&.map(&:end)&.max || 0].max if max_column < restore_ranges.map(&:end).max - Reline::IOGate.move_cursor_column(max_column) - Reline::IOGate.erase_after_cursor + @io_gate.move_cursor_column(max_column) + @io_gate.erase_after_cursor end end # Render dialog contents new_dialog_contents[y]&.each do |x_range, content| - Reline::IOGate.move_cursor_column(x_range.begin) + @io_gate.move_cursor_column(x_range.begin) @output.write "\e[0m#{content}\e[0m" end end move_cursor_up(cursor_y - dialog_y) - Reline::IOGate.move_cursor_column(cursor_column) - Reline::IOGate.show_cursor + @io_gate.move_cursor_column(cursor_column) + @io_gate.show_cursor @previous_rendered_dialog_y = dialog_y end @@ -951,7 +952,7 @@ def just_move_cursor @first_line_started_from = new_first_line_started_from @started_from = new_started_from move_cursor_down(first_line_diff + @started_from) - Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @io_gate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) false end end @@ -967,8 +968,8 @@ def just_move_cursor move_cursor_up(all_height - 1) elsif diff < 0 (-diff).times do - Reline::IOGate.move_cursor_column(0) - Reline::IOGate.erase_after_cursor + @io_gate.move_cursor_column(0) + @io_gate.erase_after_cursor move_cursor_up(1) end move_cursor_up(all_height - 1) @@ -996,13 +997,13 @@ def just_move_cursor calculate_nearest_cursor @started_from = calculate_height_by_width(prompt_width + @cursor) - 1 move_cursor_down(@started_from) - Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @io_gate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max) end private def rerender_all_lines move_cursor_up(@first_line_started_from + @started_from) - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) back = 0 new_buffer = whole_lines prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer) @@ -1024,16 +1025,16 @@ def just_move_cursor move_cursor_up(@first_line_started_from + @started_from) scroll_down(@screen_height - 1) move_cursor_up(@screen_height) - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) elsif back > old_highest_in_all scroll_down(back - 1) move_cursor_up(back - 1) elsif back < old_highest_in_all scroll_down(back) - Reline::IOGate.erase_after_cursor + @io_gate.erase_after_cursor (old_highest_in_all - back - 1).times do scroll_down(1) - Reline::IOGate.erase_after_cursor + @io_gate.erase_after_cursor end move_cursor_up(old_highest_in_all - 1) end @@ -1047,11 +1048,11 @@ def just_move_cursor @first_line_started_from = new_first_line_started_from @started_from = new_started_from if @scroll_partial_screen - Reline::IOGate.move_cursor_up(@screen_height - (@first_line_started_from + @started_from - @scroll_partial_screen) - 1) - Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @io_gate.move_cursor_up(@screen_height - (@first_line_started_from + @started_from - @scroll_partial_screen) - 1) + @io_gate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) else move_cursor_down(@first_line_started_from + @started_from - back + 1) - Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @io_gate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) end end @@ -1128,11 +1129,11 @@ def just_move_cursor @output.write "\e[0m" # clear character decorations end visual_lines.each_with_index do |line, index| - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) if line.nil? - if calculate_width(visual_lines[index - 1], true) == Reline::IOGate.get_screen_size.last + if calculate_width(visual_lines[index - 1], true) == @io_gate.get_screen_size.last # reaches the end of line - if Reline::IOGate.win? and Reline::IOGate.win_legacy_console? + if @io_gate.win? and @io_gate.win_legacy_console? # A newline is automatically inserted if a character is rendered at # eol on command prompt. else @@ -1140,17 +1141,17 @@ def just_move_cursor # after the cursor, some terminals delete the character at the # cursor position. move_cursor_down(1) - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) end else - Reline::IOGate.erase_after_cursor + @io_gate.erase_after_cursor move_cursor_down(1) - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) end next end @output.write line - if Reline::IOGate.win? and Reline::IOGate.win_legacy_console? and calculate_width(line, true) == Reline::IOGate.get_screen_size.last + if @io_gate.win? and @io_gate.win_legacy_console? and calculate_width(line, true) == @io_gate.get_screen_size.last # A newline is automatically inserted if a character is rendered at eol on command prompt. @rest_height -= 1 if @rest_height > 0 end @@ -1161,18 +1162,18 @@ def just_move_cursor end end unless visual_lines.empty? - Reline::IOGate.erase_after_cursor - Reline::IOGate.move_cursor_column(0) + @io_gate.erase_after_cursor + @io_gate.move_cursor_column(0) end if with_control # Just after rendring, so the cursor is on the last line. if finished? - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) else # Moves up from bottom of lines to the cursor position. move_cursor_up(cursor_up_from_last_line) # This logic is buggy if a fullwidth char is wrapped because there is only one halfwidth at end of a line. - Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @io_gate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) end end height @@ -1192,7 +1193,7 @@ def just_move_cursor scroll_down(@highest_in_all - @first_line_started_from) @rerender_all = true @menu_info.list.sort!.each do |item| - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) @output.write item @output.flush scroll_down(1) @@ -1202,7 +1203,7 @@ def just_move_cursor end private def clear_screen_buffer(prompt, prompt_list, prompt_width) - Reline::IOGate.clear_screen + @io_gate.clear_screen back = 0 modify_lines(whole_lines).each_with_index do |line, index| if @prompt_proc @@ -1218,8 +1219,8 @@ def just_move_cursor end move_cursor_up(back) move_cursor_down(@first_line_started_from + @started_from) - @rest_height = (Reline::IOGate.get_screen_size.first - 1) - Reline::IOGate.cursor_pos.y - Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) + @rest_height = (@io_gate.get_screen_size.first - 1) - @io_gate.cursor_pos.y + @io_gate.move_cursor_column((prompt_width + @cursor) % @screen_size.last) end def editing_mode @@ -2597,7 +2598,7 @@ def finish if @buffer_of_lines.size > 1 scroll_down(@highest_in_all - @first_line_started_from) end - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) @eof = true finish elsif @byte_pointer < @line.bytesize @@ -2994,7 +2995,7 @@ def finish if @buffer_of_lines.size > 1 scroll_down(@highest_in_all - @first_line_started_from) end - Reline::IOGate.move_cursor_column(0) + @io_gate.move_cursor_column(0) @eof = true finish else diff --git a/test/reline/test_ansi_with_terminfo.rb b/test/reline/test_ansi_with_terminfo.rb index d7f61806a6..446f001ed5 100644 --- a/test/reline/test_ansi_with_terminfo.rb +++ b/test/reline/test_ansi_with_terminfo.rb @@ -4,7 +4,7 @@ class Reline::ANSI::TestWithTerminfo < Reline::TestCase def setup Reline.send(:test_mode, ansi: true) - @config = Reline::Config.new + @config = Reline::Config.new(Reline::IOGate) Reline::IOGate.set_default_key_bindings(@config, allow_terminfo: true) end diff --git a/test/reline/test_ansi_without_terminfo.rb b/test/reline/test_ansi_without_terminfo.rb index 28b929849b..f26806b9ff 100644 --- a/test/reline/test_ansi_without_terminfo.rb +++ b/test/reline/test_ansi_without_terminfo.rb @@ -4,7 +4,7 @@ class Reline::ANSI::TestWithoutTerminfo < Reline::TestCase def setup Reline.send(:test_mode, ansi: true) - @config = Reline::Config.new + @config = Reline::Config.new(Reline::IOGate) Reline::IOGate.set_default_key_bindings(@config, allow_terminfo: false) end diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb index c08d7ba498..510b388f32 100644 --- a/test/reline/test_config.rb +++ b/test/reline/test_config.rb @@ -12,7 +12,7 @@ def setup end Dir.chdir(@tmpdir) Reline.test_mode - @config = Reline::Config.new + @config = Reline::Config.new(Reline::IOGate) end def teardown @@ -86,7 +86,7 @@ def test_string_value_with_parens_and_quotes def test_encoding_is_ascii @config.reset Reline::IOGate.reset(encoding: Encoding::US_ASCII) - @config = Reline::Config.new + @config = Reline::Config.new(Reline::IOGate) assert_equal true, @config.convert_meta end @@ -94,7 +94,7 @@ def test_encoding_is_ascii def test_encoding_is_not_ascii @config.reset Reline::IOGate.reset(encoding: Encoding::UTF_8) - @config = Reline::Config.new + @config = Reline::Config.new(Reline::IOGate) assert_equal nil, @config.convert_meta end diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 18a2448539..eb2fc91d29 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -4,7 +4,7 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase def setup Reline.send(:test_mode) @prompt = '> ' - @config = Reline::Config.new # Emacs mode is default + @config = Reline::Config.new(Reline::IOGate) # Emacs mode is default @config.autocompletion = false Reline::HISTORY.instance_variable_set(:@config, @config) Reline::HISTORY.clear diff --git a/test/reline/test_key_actor_vi.rb b/test/reline/test_key_actor_vi.rb index 6e1d9dbbda..cf4fedf671 100644 --- a/test/reline/test_key_actor_vi.rb +++ b/test/reline/test_key_actor_vi.rb @@ -4,7 +4,7 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase def setup Reline.send(:test_mode) @prompt = '> ' - @config = Reline::Config.new + @config = Reline::Config.new(Reline::IOGate) @config.read_lines(<<~LINES.split(/(?<=\n)/)) set editing-mode vi LINES diff --git a/test/reline/test_key_stroke.rb b/test/reline/test_key_stroke.rb index d377a1e972..2dbf4e1194 100644 --- a/test/reline/test_key_stroke.rb +++ b/test/reline/test_key_stroke.rb @@ -14,7 +14,7 @@ def to_keys } def test_match_status - config = Reline::Config.new + config = Reline::Config.new(Reline::IOGate) { 'a' => 'xx', 'ab' => 'y', @@ -37,7 +37,7 @@ def test_match_status end def test_expand - config = Reline::Config.new + config = Reline::Config.new(Reline::IOGate) { 'abc' => '123', }.each_pair do |key, func| @@ -48,7 +48,7 @@ def test_expand end def test_oneshot_key_bindings - config = Reline::Config.new + config = Reline::Config.new(Reline::IOGate) { 'abc' => '123', }.each_pair do |key, func| @@ -60,7 +60,7 @@ def test_oneshot_key_bindings end def test_with_reline_key - config = Reline::Config.new + config = Reline::Config.new(Reline::IOGate) { [ Reline::Key.new(100, 228, true), # Alt+d diff --git a/test/reline/test_line_editor.rb b/test/reline/test_line_editor.rb index 8399e76e92..b3748d1fe0 100644 --- a/test/reline/test_line_editor.rb +++ b/test/reline/test_line_editor.rb @@ -3,8 +3,8 @@ class Reline::LineEditor::Test < Reline::TestCase def test_range_subtract - dummy_config = nil - editor = Reline::LineEditor.new(dummy_config, 'ascii-8bit') + config = Reline::Config.new(Reline::IOGate) + editor = Reline::LineEditor.new(config, 'ascii-8bit') base_ranges = [3...5, 4...10, 6...8, 12...15, 15...20] subtract_ranges = [5...7, 8...9, 11...13, 17...18, 18...19] expected_result = [3...5, 7...8, 9...10, 13...17, 19...20] diff --git a/test/reline/test_macro.rb b/test/reline/test_macro.rb index 76a677c834..ccb023ea51 100644 --- a/test/reline/test_macro.rb +++ b/test/reline/test_macro.rb @@ -3,7 +3,7 @@ class Reline::MacroTest < Reline::TestCase def setup Reline.send(:test_mode) - @config = Reline::Config.new + @config = Reline::Config.new(Reline::IOGate) @encoding = Reline::IOGate.encoding @line_editor = Reline::LineEditor.new(@config, @encoding) @line_editor.instance_variable_set(:@screen_size, [24, 80]) diff --git a/test/reline/test_string_processing.rb b/test/reline/test_string_processing.rb index 5db97545da..acc5a447cc 100644 --- a/test/reline/test_string_processing.rb +++ b/test/reline/test_string_processing.rb @@ -4,7 +4,7 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase def setup Reline.send(:test_mode) @prompt = '> ' - @config = Reline::Config.new + @config = Reline::Config.new(Reline::IOGate) Reline::HISTORY.instance_variable_set(:@config, @config) @encoding = Reline::IOGate.encoding @line_editor = Reline::LineEditor.new(@config, @encoding)