From e61471950798b310c9f573147329888877fe7317 Mon Sep 17 00:00:00 2001 From: tompng Date: Sun, 12 Jan 2025 21:41:16 +0900 Subject: [PATCH] Show a message "Inspecting..." while generating pretty_print content --- lib/irb/pager.rb | 3 ++- test/irb/yamatanooroti/test_rendering.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/irb/pager.rb b/lib/irb/pager.rb index 3c9bee9aa..1a56977bd 100644 --- a/lib/irb/pager.rb +++ b/lib/irb/pager.rb @@ -56,10 +56,11 @@ def should_page? def page_with_preview(width, height, formatter_proc) overflow_callback = ->(lines) do modified_output = formatter_proc.call(lines.join, true) - content, = take_first_page(width, height - 1) {|o| o.write modified_output } + content, = take_first_page(width, [height - 2, 0].max) {|o| o.write modified_output } content = content.chomp content = "#{content}\e[0m" if Color.colorable? $stdout.puts content + $stdout.puts 'Inspecting...' end out = PageOverflowIO.new(width, height, overflow_callback) yield out diff --git a/test/irb/yamatanooroti/test_rendering.rb b/test/irb/yamatanooroti/test_rendering.rb index 7bc152ed2..fd1c96aac 100644 --- a/test/irb/yamatanooroti/test_rendering.rb +++ b/test/irb/yamatanooroti/test_rendering.rb @@ -400,7 +400,7 @@ def test_pretty_print_preview_with_slow_inspect write("o2 = Object.new; def o2.inspect; sleep 10; end\n") # preview should be shown even if pretty_print is not completed. write("[o1] * 20 + [o2]\n") - assert_screen(/=>\n\[INSPECT,\n( INSPECT,\n){7}/) + assert_screen(/=>\n\[INSPECT,\n( INSPECT,\n){6}Inspecting.../) write("\C-c") # abort pretty_print write("'foo' + 'bar'\n") # eval something to make sure IRB resumes assert_screen(/foobar/)