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

[ruby/reline] Drop prompt list cache when num of lines is changed

https://github.com/ruby/reline/commit/1959e22043
This commit is contained in:
aycabta 2020-11-21 02:59:38 +09:00
parent 2910684c45
commit 37a574b527
2 changed files with 15 additions and 1 deletions

View file

@ -50,6 +50,8 @@ class Reline::LineEditor
CompletionJourneyData = Struct.new('CompletionJourneyData', :preposing, :postposing, :list, :pointer)
MenuInfo = Struct.new('MenuInfo', :target, :list)
PROMPT_LIST_CACHE_TIMEOUT = 0.5
def initialize(config, encoding)
@config = config
@completion_append_character = ''
@ -78,7 +80,7 @@ class Reline::LineEditor
end
return [prompt, calculate_width(prompt, true), [prompt] * buffer.size] if simplified_rendering?
if @prompt_proc
if @cached_prompt_list and Time.now.to_f < (@prompt_cache_time + 0.5)
if @cached_prompt_list and Time.now.to_f < (@prompt_cache_time + PROMPT_LIST_CACHE_TIMEOUT) and buffer.size == @cached_prompt_list.size
prompt_list = @cached_prompt_list
else
prompt_list = @cached_prompt_list = @prompt_proc.(buffer)

View file

@ -398,6 +398,18 @@ begin
EOC
end
def test_prompt_list_caching
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/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
private def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content