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:
parent
a66bc2c011
commit
3b7862c8e8
3 changed files with 9 additions and 5 deletions
|
@ -46,10 +46,13 @@ module Reline
|
||||||
end
|
end
|
||||||
|
|
||||||
def push(*val)
|
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) }))
|
super(*(val.map{ |v| String.new(v, encoding: Encoding::default_external) }))
|
||||||
end
|
end
|
||||||
|
|
||||||
def <<(val)
|
def <<(val)
|
||||||
|
shift if size + 1 > @@config.history_size
|
||||||
super(String.new(val, encoding: Encoding::default_external))
|
super(String.new(val, encoding: Encoding::default_external))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
||||||
def setup
|
def setup
|
||||||
Reline.send(:test_mode)
|
Reline.send(:test_mode)
|
||||||
@prompt = '> '
|
@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)
|
@encoding = (RELINE_TEST_ENCODING rescue Encoding.default_external)
|
||||||
@line_editor = Reline::LineEditor.new(@config)
|
|
||||||
@line_editor.reset(@prompt, @encoding)
|
@line_editor.reset(@prompt, @encoding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,13 @@ class Reline::KeyActor::ViInsert::Test < Reline::TestCase
|
||||||
def setup
|
def setup
|
||||||
Reline.send(:test_mode)
|
Reline.send(:test_mode)
|
||||||
@prompt = '> '
|
@prompt = '> '
|
||||||
@config = Reline::Config.new
|
@config = Reline.class_variable_get(:@@config) # Emacs mode is default
|
||||||
@config.read_lines(<<~LINES.split(/(?<=\n)/))
|
@config.read_lines(<<~LINES.split(/(?<=\n)/))
|
||||||
set editing-mode vi
|
set editing-mode vi
|
||||||
LINES
|
LINES
|
||||||
@line_editor = Reline::LineEditor.new(@config)
|
@line_editor = Reline.class_variable_get(:@@line_editor)
|
||||||
@line_editor.reset(@prompt, (RELINE_TEST_ENCODING rescue Encoding.default_external))
|
@encoding = (RELINE_TEST_ENCODING rescue Encoding.default_external)
|
||||||
|
@line_editor.reset(@prompt, @encoding)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_vi_command_mode
|
def test_vi_command_mode
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue