Skip to content

Commit

Permalink
Show a message "Inspecting..." while generating pretty_print content
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Jan 12, 2025
1 parent 1ad6498 commit e614719
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/irb/pager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/irb/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down

0 comments on commit e614719

Please sign in to comment.