1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Use existing instances for LineEditor and Config

This commit is contained in:
aycabta 2019-05-29 05:53:14 +09:00
parent a66bc2c011
commit 3b7862c8e8
3 changed files with 9 additions and 5 deletions

View file

@ -46,10 +46,13 @@ module Reline
end
def push(*val)
diff = size + val.size - @@config.history_size
shift(diff) if diff > 0
super(*(val.map{ |v| String.new(v, encoding: Encoding::default_external) }))
end
def <<(val)
shift if size + 1 > @@config.history_size
super(String.new(val, encoding: Encoding::default_external))
end

View file

@ -4,9 +4,9 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
def setup
Reline.send(:test_mode)
@prompt = '> '
@config = Reline::Config.new # Emacs mode is default
@config = Reline.class_variable_get(:@@config) # Emacs mode is default
@line_editor = Reline.class_variable_get(:@@line_editor)
@encoding = (RELINE_TEST_ENCODING rescue Encoding.default_external)
@line_editor = Reline::LineEditor.new(@config)
@line_editor.reset(@prompt, @encoding)
end

View file

@ -4,12 +4,13 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
def setup
Reline.send(:test_mode)
@prompt = '> '
@config = Reline::Config.new
@config = Reline.class_variable_get(:@@config) # Emacs mode is default
@config.read_lines(<<~LINES.split(/(?<=\n)/))
set editing-mode vi
LINES
@line_editor = Reline::LineEditor.new(@config)
@line_editor.reset(@prompt, (RELINE_TEST_ENCODING rescue Encoding.default_external))
@line_editor = Reline.class_variable_get(:@@line_editor)
@encoding = (RELINE_TEST_ENCODING rescue Encoding.default_external)
@line_editor.reset(@prompt, @encoding)
end
def test_vi_command_mode