Skip to content

Commit

Permalink
[ruby/reline] Drop prompt list cache when num of lines is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Dec 4, 2020
1 parent 2910684 commit 37a574b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/reline/line_editor.rb
Expand Up @@ -50,6 +50,8 @@ module CompletionState
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 = ''
Expand Down Expand Up @@ -78,7 +80,7 @@ def simplified_rendering?
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)
Expand Down
12 changes: 12 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Expand Up @@ -398,6 +398,18 @@ def test_binding_for_vi_movement_mode
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
Expand Down

0 comments on commit 37a574b

Please sign in to comment.