ruby-changes:63930
From: aycabta <ko1@a...>
Date: Sat, 5 Dec 2020 03:09:27 +0900 (JST)
Subject: [ruby-changes:63930] 37a574b527 (master): [ruby/reline] Drop prompt list cache when num of lines is changed
https://git.ruby-lang.org/ruby.git/commit/?id=37a574b527 From 37a574b527f2c612be46ec8038ff52bf861bf82f Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sat, 21 Nov 2020 02:59:38 +0900 Subject: [ruby/reline] Drop prompt list cache when num of lines is changed https://github.com/ruby/reline/commit/1959e22043 diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 1328668..868e31a 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -50,6 +50,8 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L50 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 https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L80 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 dea3e7f..a2af807 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -398,6 +398,18 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L398 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/