From 37a574b527f2c612be46ec8038ff52bf861bf82f Mon Sep 17 00:00:00 2001 From: aycabta Date: Sat, 21 Nov 2020 02:59:38 +0900 Subject: [PATCH] [ruby/reline] Drop prompt list cache when num of lines is changed https://github.com/ruby/reline/commit/1959e22043 --- lib/reline/line_editor.rb | 4 +++- test/reline/yamatanooroti/test_rendering.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 13286683a3..868e31aca8 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -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) diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index dea3e7ff47..a2af80768d 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -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