[ruby/reline] Reline 0.5.0.pre

(https://github.com/ruby/reline/pull/614)

* Re-architecture LineEditor's internal state and rendering

* Fix test related to LineEditor re-architecture

* Bump to 0.5.0.pre.1

* Hide cursor only when updating screen. Frequent hide&show makes cursor flickering.

* Simplify rerender call from reline.rb

* Simplify handle_cleared

It only need to clear screen. line_editor.rerender will be called later.

* Add description of updating pasting_state inserts continuous_insertion_buffer

* Use meaningful block parameter

Co-authored-by: Stan Lo <stan001212@gmail.com>

* Fix use of `@cursor_y`

Fix bug updating `@cursor_y`. Do not use `@cursor_y` while updating dialog because it is not current cursor position but cursor position at last rendered time.

* Remove useless instance_variable_set in test

These instance variables are already removed from LineEditor

* Always initialize instance variables to avoid ruby 2.7 warning, remove unused instance variable

* Call update_dialogs from reline.rb before first render

* Combine state representing rendered screen information into `@rendered_screen`

* Rename editor_cursor_ to wrapped_cursor

It represents cursor position of word wrapped whole content

* Remove unused code, tweak, add comment

---------

3fa376217d

Co-authored-by: Stan Lo <stan001212@gmail.com>
This commit is contained in:
tomoya ishida 2024-03-19 23:17:20 +09:00 committed by git
parent e127289632
commit d7bc6f0eff
11 changed files with 824 additions and 1424 deletions

View file

@ -78,7 +78,6 @@ module Reline
@dialog_proc_list = {} @dialog_proc_list = {}
yield self yield self
@completion_quote_character = nil @completion_quote_character = nil
@bracketed_paste_finished = false
end end
def io_gate def io_gate
@ -278,8 +277,13 @@ module Reline
Reline::HISTORY << whole_buffer Reline::HISTORY << whole_buffer
end end
line_editor.reset_line if line_editor.whole_buffer.nil? if line_editor.eof?
whole_buffer line_editor.reset_line
# Return nil if the input is aborted by C-d.
nil
else
whole_buffer
end
end end
end end
@ -326,7 +330,7 @@ module Reline
line_editor.prompt_proc = prompt_proc line_editor.prompt_proc = prompt_proc
line_editor.auto_indent_proc = auto_indent_proc line_editor.auto_indent_proc = auto_indent_proc
line_editor.dig_perfect_match_proc = dig_perfect_match_proc line_editor.dig_perfect_match_proc = dig_perfect_match_proc
line_editor.pre_input_hook = pre_input_hook pre_input_hook&.call
@dialog_proc_list.each_pair do |name_sym, d| @dialog_proc_list.each_pair do |name_sym, d|
line_editor.add_dialog_proc(name_sym, d.dialog_proc, d.context) line_editor.add_dialog_proc(name_sym, d.dialog_proc, d.context)
end end
@ -337,30 +341,24 @@ module Reline
io_gate.set_default_key_bindings(config) io_gate.set_default_key_bindings(config)
end end
line_editor.print_nomultiline_prompt(prompt)
line_editor.update_dialogs
line_editor.rerender line_editor.rerender
begin begin
line_editor.set_signal_handlers line_editor.set_signal_handlers
prev_pasting_state = false
loop do loop do
prev_pasting_state = io_gate.in_pasting?
read_io(config.keyseq_timeout) { |inputs| read_io(config.keyseq_timeout) { |inputs|
line_editor.set_pasting_state(io_gate.in_pasting?) line_editor.set_pasting_state(io_gate.in_pasting?)
inputs.each { |c| inputs.each { |key| line_editor.update(key) }
line_editor.input_key(c)
line_editor.rerender
}
if @bracketed_paste_finished
line_editor.rerender_all
@bracketed_paste_finished = false
end
} }
if prev_pasting_state == true and not io_gate.in_pasting? and not line_editor.finished? if line_editor.finished?
line_editor.set_pasting_state(false) line_editor.render_finished
prev_pasting_state = false break
line_editor.rerender_all else
line_editor.set_pasting_state(io_gate.in_pasting?)
line_editor.rerender
end end
break if line_editor.finished?
end end
io_gate.move_cursor_column(0) io_gate.move_cursor_column(0)
rescue Errno::EIO rescue Errno::EIO
@ -395,7 +393,6 @@ module Reline
c = io_gate.getc(Float::INFINITY) c = io_gate.getc(Float::INFINITY)
if c == -1 if c == -1
result = :unmatched result = :unmatched
@bracketed_paste_finished = true
else else
buffer << c buffer << c
result = key_stroke.match_status(buffer) result = key_stroke.match_status(buffer)

View file

@ -57,7 +57,7 @@ class Reline::GeneralIO
end end
def self.get_screen_size def self.get_screen_size
[1, 1] [24, 80]
end end
def self.cursor_pos def self.cursor_pos

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,3 @@
module Reline module Reline
VERSION = '0.4.3' VERSION = '0.5.0.pre.1'
end end

View file

@ -29,12 +29,19 @@ module Reline
else else
encoding = Encoding::UTF_8 encoding = Encoding::UTF_8
end end
@original_get_screen_size = IOGate.method(:get_screen_size)
IOGate.singleton_class.remove_method(:get_screen_size)
def IOGate.get_screen_size
[24, 80]
end
Reline::GeneralIO.reset(encoding: encoding) unless ansi Reline::GeneralIO.reset(encoding: encoding) unless ansi
core.config.instance_variable_set(:@test_mode, true) core.config.instance_variable_set(:@test_mode, true)
core.config.reset core.config.reset
end end
def test_reset def test_reset
IOGate.singleton_class.remove_method(:get_screen_size)
IOGate.define_singleton_method(:get_screen_size, @original_get_screen_size)
remove_const('IOGate') remove_const('IOGate')
const_set('IOGate', @original_iogate) const_set('IOGate', @original_iogate)
Reline::GeneralIO.reset Reline::GeneralIO.reset
@ -147,11 +154,22 @@ class Reline::TestCase < Test::Unit::TestCase
end end
def assert_cursor(expected) def assert_cursor(expected)
assert_equal(expected, @line_editor.instance_variable_get(:@cursor)) # This test satisfies nothing because there is no `@cursor` anymore
# Test editor_cursor_position instead
cursor_x = @line_editor.instance_eval do
line_before_cursor = whole_lines[@line_index].byteslice(0, @byte_pointer)
Reline::Unicode.calculate_width(line_before_cursor)
end
assert_equal(expected, cursor_x)
end end
def assert_cursor_max(expected) def assert_cursor_max(expected)
assert_equal(expected, @line_editor.instance_variable_get(:@cursor_max)) # This test satisfies nothing because there is no `@cursor_max` anymore
cursor_max = @line_editor.instance_eval do
line = whole_lines[@line_index]
Reline::Unicode.calculate_width(line)
end
assert_equal(expected, cursor_max)
end end
def assert_line_index(expected) def assert_line_index(expected)

View file

@ -1737,19 +1737,19 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_cursor_max(0) assert_cursor_max(0)
input_keys("\C-r123") input_keys("\C-r123")
assert_line('1234') assert_line('1234')
assert_byte_pointer_size('') assert_byte_pointer_size('1234')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) # doesn't determine yet assert_cursor_max(4)
input_keys("\C-ha") input_keys("\C-ha")
assert_line('12aa') assert_line('12aa')
assert_byte_pointer_size('') assert_byte_pointer_size('12aa')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
input_keys("\C-h3") input_keys("\C-h3")
assert_line('1235') assert_line('1235')
assert_byte_pointer_size('') assert_byte_pointer_size('1235')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
end end
def test_search_history_to_front def test_search_history_to_front
@ -1764,19 +1764,19 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_cursor_max(0) assert_cursor_max(0)
input_keys("\C-s123") input_keys("\C-s123")
assert_line('1235') assert_line('1235')
assert_byte_pointer_size('') assert_byte_pointer_size('1235')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) # doesn't determine yet assert_cursor_max(4)
input_keys("\C-ha") input_keys("\C-ha")
assert_line('12aa') assert_line('12aa')
assert_byte_pointer_size('') assert_byte_pointer_size('12aa')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
input_keys("\C-h3") input_keys("\C-h3")
assert_line('1234') assert_line('1234')
assert_byte_pointer_size('') assert_byte_pointer_size('1234')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
end end
def test_search_history_front_and_back def test_search_history_front_and_back
@ -1791,24 +1791,24 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_cursor_max(0) assert_cursor_max(0)
input_keys("\C-s12") input_keys("\C-s12")
assert_line('1235') assert_line('1235')
assert_byte_pointer_size('') assert_byte_pointer_size('1235')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) # doesn't determine yet assert_cursor_max(4)
input_keys("\C-s") input_keys("\C-s")
assert_line('12aa') assert_line('12aa')
assert_byte_pointer_size('') assert_byte_pointer_size('12aa')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
input_keys("\C-r") input_keys("\C-r")
assert_line('12aa') assert_line('12aa')
assert_byte_pointer_size('') assert_byte_pointer_size('12aa')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
input_keys("\C-r") input_keys("\C-r")
assert_line('1235') assert_line('1235')
assert_byte_pointer_size('') assert_byte_pointer_size('1235')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
end end
def test_search_history_back_and_front def test_search_history_back_and_front
@ -1823,24 +1823,24 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_cursor_max(0) assert_cursor_max(0)
input_keys("\C-r12") input_keys("\C-r12")
assert_line('1234') assert_line('1234')
assert_byte_pointer_size('') assert_byte_pointer_size('1234')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) # doesn't determine yet assert_cursor_max(4)
input_keys("\C-r") input_keys("\C-r")
assert_line('12aa') assert_line('12aa')
assert_byte_pointer_size('') assert_byte_pointer_size('12aa')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
input_keys("\C-s") input_keys("\C-s")
assert_line('12aa') assert_line('12aa')
assert_byte_pointer_size('') assert_byte_pointer_size('12aa')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
input_keys("\C-s") input_keys("\C-s")
assert_line('1234') assert_line('1234')
assert_byte_pointer_size('') assert_byte_pointer_size('1234')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
end end
def test_search_history_to_back_in_the_middle_of_histories def test_search_history_to_back_in_the_middle_of_histories
@ -1877,14 +1877,14 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_cursor_max(0) assert_cursor_max(0)
input_keys("\C-r123") input_keys("\C-r123")
assert_line('1234') assert_line('1234')
assert_byte_pointer_size('') assert_byte_pointer_size('1234')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) # doesn't determine yet assert_cursor_max(4)
input_keys("\C-r") input_keys("\C-r")
assert_line('1235') assert_line('1235')
assert_byte_pointer_size('') assert_byte_pointer_size('1235')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
end end
def test_search_history_by_last_determined def test_search_history_by_last_determined
@ -1899,9 +1899,9 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_cursor_max(0) assert_cursor_max(0)
input_keys("\C-r123") input_keys("\C-r123")
assert_line('1234') assert_line('1234')
assert_byte_pointer_size('') assert_byte_pointer_size('1234')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) # doesn't determine yet assert_cursor_max(4)
input_keys("\C-j") input_keys("\C-j")
assert_line('1234') assert_line('1234')
assert_byte_pointer_size('') assert_byte_pointer_size('')
@ -1919,9 +1919,9 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_cursor_max(0) assert_cursor_max(0)
input_keys("\C-r") input_keys("\C-r")
assert_line('1235') assert_line('1235')
assert_byte_pointer_size('') assert_byte_pointer_size('1235')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) assert_cursor_max(4)
end end
def test_search_history_with_isearch_terminator def test_search_history_with_isearch_terminator
@ -1939,9 +1939,9 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_cursor_max(0) assert_cursor_max(0)
input_keys("\C-r12a") input_keys("\C-r12a")
assert_line('12aa') assert_line('12aa')
assert_byte_pointer_size('') assert_byte_pointer_size('12aa')
assert_cursor(0) assert_cursor(4)
assert_cursor_max(0) # doesn't determine yet assert_cursor_max(4)
input_keys('Y') input_keys('Y')
assert_line('12aa') assert_line('12aa')
assert_byte_pointer_size('') assert_byte_pointer_size('')
@ -2013,7 +2013,7 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
$VERBOSE = verbose $VERBOSE = verbose
@line_editor.output_modifier_proc = proc { |output| Reline::Unicode.escape_for_print(output) } @line_editor.output_modifier_proc = proc { |output| Reline::Unicode.escape_for_print(output) }
input_keys("abcdef\n") input_keys("abcdef\n")
result = @line_editor.__send__(:modify_lines, @line_editor.whole_lines) result = @line_editor.__send__(:modify_lines, @line_editor.whole_lines, @line_editor.finished?)
$/ = nil $/ = nil
assert_equal(['abcdef'], result) assert_equal(['abcdef'], result)
ensure ensure

View file

@ -1,13 +1,124 @@
require_relative 'helper' require_relative 'helper'
require 'reline/line_editor' require 'reline/line_editor'
require 'stringio'
class Reline::LineEditor::Test < Reline::TestCase class Reline::LineEditor
def test_range_subtract class RenderLineDifferentialTest < Reline::TestCase
dummy_config = nil def setup
editor = Reline::LineEditor.new(dummy_config, 'ascii-8bit') verbose, $VERBOSE = $VERBOSE, nil
base_ranges = [3...5, 4...10, 6...8, 12...15, 15...20] @line_editor = Reline::LineEditor.new(nil, Encoding::UTF_8)
subtract_ranges = [5...7, 8...9, 11...13, 17...18, 18...19] @original_iogate = Reline::IOGate
expected_result = [3...5, 7...8, 9...10, 13...17, 19...20] @output = StringIO.new
assert_equal expected_result, editor.send(:range_subtract, base_ranges, subtract_ranges) @line_editor.instance_variable_set(:@screen_size, [24, 80])
@line_editor.instance_variable_set(:@output, @output)
Reline.send(:remove_const, :IOGate)
Reline.const_set(:IOGate, Object.new)
Reline::IOGate.instance_variable_set(:@output, @output)
def (Reline::IOGate).move_cursor_column(col)
@output << "[COL_#{col}]"
end
def (Reline::IOGate).erase_after_cursor
@output << '[ERASE]'
end
ensure
$VERBOSE = verbose
end
def assert_output(expected)
@output.reopen(+'')
yield
actual = @output.string
assert_equal(expected, actual.gsub("\e[0m", ''))
end
def teardown
Reline.send(:remove_const, :IOGate)
Reline.const_set(:IOGate, @original_iogate)
end
def test_line_increase_decrease
assert_output '[COL_0]bb' do
@line_editor.render_line_differential([[0, 1, 'a']], [[0, 2, 'bb']])
end
assert_output '[COL_0]b[COL_1][ERASE]' do
@line_editor.render_line_differential([[0, 2, 'aa']], [[0, 1, 'b']])
end
end
def test_dialog_appear_disappear
assert_output '[COL_3]dialog' do
@line_editor.render_line_differential([[0, 1, 'a']], [[0, 1, 'a'], [3, 6, 'dialog']])
end
assert_output '[COL_3]dialog' do
@line_editor.render_line_differential([[0, 10, 'a' * 10]], [[0, 10, 'a' * 10], [3, 6, 'dialog']])
end
assert_output '[COL_1][ERASE]' do
@line_editor.render_line_differential([[0, 1, 'a'], [3, 6, 'dialog']], [[0, 1, 'a']])
end
assert_output '[COL_3]aaaaaa' do
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 10, 'a' * 10]])
end
end
def test_dialog_change
assert_output '[COL_3]DIALOG' do
@line_editor.render_line_differential([[0, 2, 'a'], [3, 6, 'dialog']], [[0, 2, 'a'], [3, 6, 'DIALOG']])
end
assert_output '[COL_3]DIALOG' do
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 10, 'a' * 10], [3, 6, 'DIALOG']])
end
end
def test_update_under_dialog
assert_output '[COL_0]b[COL_1] ' do
@line_editor.render_line_differential([[0, 2, 'aa'], [4, 6, 'dialog']], [[0, 1, 'b'], [4, 6, 'dialog']])
end
assert_output '[COL_0]bbb[COL_9]b' do
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 10, 'b' * 10], [3, 6, 'dialog']])
end
assert_output '[COL_0]b[COL_1] [COL_9][ERASE]' do
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 1, 'b'], [3, 6, 'dialog']])
end
end
def test_dialog_move
assert_output '[COL_3]dialog[COL_9][ERASE]' do
@line_editor.render_line_differential([[0, 1, 'a'], [4, 6, 'dialog']], [[0, 1, 'a'], [3, 6, 'dialog']])
end
assert_output '[COL_4] [COL_5]dialog' do
@line_editor.render_line_differential([[0, 1, 'a'], [4, 6, 'dialog']], [[0, 1, 'a'], [5, 6, 'dialog']])
end
assert_output '[COL_2]dialog[COL_8]a' do
@line_editor.render_line_differential([[0, 10, 'a' * 10], [3, 6, 'dialog']], [[0, 10, 'a' * 10], [2, 6, 'dialog']])
end
assert_output '[COL_2]a[COL_3]dialog' do
@line_editor.render_line_differential([[0, 10, 'a' * 10], [2, 6, 'dialog']], [[0, 10, 'a' * 10], [3, 6, 'dialog']])
end
end
def test_complicated
state_a = [nil, [19, 7, 'bbbbbbb'], [15, 8, 'cccccccc'], [10, 5, 'ddddd'], [18, 4, 'eeee'], [1, 3, 'fff'], [17, 2, 'gg'], [7, 1, 'h']]
state_b = [[5, 9, 'aaaaaaaaa'], nil, [15, 8, 'cccccccc'], nil, [18, 4, 'EEEE'], [25, 4, 'ffff'], [17, 2, 'gg'], [2, 2, 'hh']]
# state_a: " fff h dddddccggeeecbbb"
# state_b: " hh aaaaaaaaa ccggEEEc ffff"
assert_output '[COL_1] [COL_2]hh[COL_5]aaaaaaaaa[COL_14] [COL_19]EEE[COL_23] [COL_25]ffff' do
@line_editor.render_line_differential(state_a, state_b)
end
assert_output '[COL_1]fff[COL_5] [COL_7]h[COL_8] [COL_10]ddddd[COL_19]eee[COL_23]bbb[COL_26][ERASE]' do
@line_editor.render_line_differential(state_b, state_a)
end
end
end end
end end

View file

@ -6,7 +6,6 @@ class Reline::MacroTest < Reline::TestCase
@config = Reline::Config.new @config = Reline::Config.new
@encoding = Reline.core.encoding @encoding = Reline.core.encoding
@line_editor = Reline::LineEditor.new(@config, @encoding) @line_editor = Reline::LineEditor.new(@config, @encoding)
@line_editor.instance_variable_set(:@screen_size, [24, 80])
@output = @line_editor.output = File.open(IO::NULL, "w") @output = @line_editor.output = File.open(IO::NULL, "w")
end end

View file

@ -30,10 +30,7 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase
@line_editor.instance_variable_set(:@is_multiline, true) @line_editor.instance_variable_set(:@is_multiline, true)
@line_editor.instance_variable_set(:@buffer_of_lines, buf) @line_editor.instance_variable_set(:@buffer_of_lines, buf)
@line_editor.instance_variable_set(:@line, buf[1])
@line_editor.instance_variable_set(:@byte_pointer, 3) @line_editor.instance_variable_set(:@byte_pointer, 3)
@line_editor.instance_variable_set(:@cursor, 3)
@line_editor.instance_variable_set(:@cursor_max, 11)
@line_editor.instance_variable_set(:@line_index, 1) @line_editor.instance_variable_set(:@line_index, 1)
@line_editor.instance_variable_set(:@completion_proc, proc { |target| @line_editor.instance_variable_set(:@completion_proc, proc { |target|
assert_equal('p', target) assert_equal('p', target)
@ -42,10 +39,7 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase
@line_editor.instance_variable_set(:@is_multiline, true) @line_editor.instance_variable_set(:@is_multiline, true)
@line_editor.instance_variable_set(:@buffer_of_lines, buf) @line_editor.instance_variable_set(:@buffer_of_lines, buf)
@line_editor.instance_variable_set(:@line, buf[1])
@line_editor.instance_variable_set(:@byte_pointer, 6) @line_editor.instance_variable_set(:@byte_pointer, 6)
@line_editor.instance_variable_set(:@cursor, 6)
@line_editor.instance_variable_set(:@cursor_max, 11)
@line_editor.instance_variable_set(:@line_index, 1) @line_editor.instance_variable_set(:@line_index, 1)
@line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post| @line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post|
assert_equal('puts', target) assert_equal('puts', target)
@ -54,10 +48,7 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase
}) })
@line_editor.__send__(:call_completion_proc) @line_editor.__send__(:call_completion_proc)
@line_editor.instance_variable_set(:@line, buf[0])
@line_editor.instance_variable_set(:@byte_pointer, 6) @line_editor.instance_variable_set(:@byte_pointer, 6)
@line_editor.instance_variable_set(:@cursor, 6)
@line_editor.instance_variable_set(:@cursor_max, 8)
@line_editor.instance_variable_set(:@line_index, 0) @line_editor.instance_variable_set(:@line_index, 0)
@line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post| @line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post|
assert_equal('ho', target) assert_equal('ho', target)
@ -66,10 +57,7 @@ class Reline::LineEditor::StringProcessingTest < Reline::TestCase
}) })
@line_editor.__send__(:call_completion_proc) @line_editor.__send__(:call_completion_proc)
@line_editor.instance_variable_set(:@line, buf[2])
@line_editor.instance_variable_set(:@byte_pointer, 1) @line_editor.instance_variable_set(:@byte_pointer, 1)
@line_editor.instance_variable_set(:@cursor, 1)
@line_editor.instance_variable_set(:@cursor_max, 3)
@line_editor.instance_variable_set(:@line_index, 2) @line_editor.instance_variable_set(:@line_index, 2)
@line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post| @line_editor.instance_variable_set(:@completion_proc, proc { |target, pre, post|
assert_equal('e', target) assert_equal('e', target)

View file

@ -9,10 +9,6 @@ require 'optparse'
require_relative 'termination_checker' require_relative 'termination_checker'
opt = OptionParser.new opt = OptionParser.new
opt.on('--prompt-list-cache-timeout VAL') { |v|
Reline::LineEditor.__send__(:remove_const, :PROMPT_LIST_CACHE_TIMEOUT)
Reline::LineEditor::PROMPT_LIST_CACHE_TIMEOUT = v.to_f
}
opt.on('--dynamic-prompt') { opt.on('--dynamic-prompt') {
Reline.prompt_proc = proc { |lines| Reline.prompt_proc = proc { |lines|
lines.each_with_index.map { |l, i| lines.each_with_index.map { |l, i|

View file

@ -464,6 +464,9 @@ begin
write("def a\n 8\nend\ndef b\n 3\nend\C-s8") write("def a\n 8\nend\ndef b\n 3\nend\C-s8")
close close
assert_screen(<<~EOC) assert_screen(<<~EOC)
prompt> 8
prompt> end
=> :a
(i-search)`8'def a (i-search)`8'def a
(i-search)`8' 8 (i-search)`8' 8
(i-search)`8'end (i-search)`8'end
@ -475,6 +478,9 @@ begin
write("def a\n 8\nend\ndef b\n 3\nend\C-r8\C-j") write("def a\n 8\nend\ndef b\n 3\nend\C-r8\C-j")
close close
assert_screen(<<~EOC) assert_screen(<<~EOC)
prompt> 8
prompt> end
=> :a
prompt> def a prompt> def a
prompt> 8 prompt> 8
prompt> end prompt> end
@ -495,18 +501,6 @@ begin
EOC EOC
end end
def test_prompt_list_caching
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --prompt-list-cache-timeout 10 --dynamic-prompt}, startup_message: 'Multiline REPL.')
write("def hoge\n 3\nend")
close
assert_screen(<<~EOC)
Multiline REPL.
[0000]> def hoge
[0001]> 3
[0002]> end
EOC
end
def test_broken_prompt_list def test_broken_prompt_list
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --broken-dynamic-prompt}, startup_message: 'Multiline REPL.') start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --broken-dynamic-prompt}, startup_message: 'Multiline REPL.')
write("def hoge\n 3\nend") write("def hoge\n 3\nend")
@ -1026,8 +1020,8 @@ begin
iterate_over_face_configs do |config_name, config_file| iterate_over_face_configs do |config_name, config_file|
start_terminal(10, 50, %W{ruby -I#{@pwd}/lib -r#{config_file.path} #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.') start_terminal(10, 50, %W{ruby -I#{@pwd}/lib -r#{config_file.path} #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
write("\n" * 10) write("\n" * 10)
write("if 1\n sSt\nend") write("if 1\n sSts\nend")
write("\C-p\C-h\C-e") write("\C-p\C-h\C-e\C-h")
close close
assert_screen(<<~'EOC') assert_screen(<<~'EOC')
prompt> prompt>
@ -1054,8 +1048,8 @@ begin
prompt> 2 prompt> 2
prompt> 3# prompt> 3#
prompt> 4 prompt> 4
prompt> 5 prompt> 5 Ruby is...
prompt> 6 Ruby is... prompt> 6 A dynamic, open source programming
EOC EOC
end end
end end