class IRB::Pager
The implementation of this class is borrowed from RDoc’s lib/rdoc/ri/driver.rb. Please do NOT use this class directly outside of IRB
.
Constants
- PAGE_COMMANDS
Public Class Methods
page
(retain_content: false) { |pager| ... }
# File lib/irb/pager.rb, line 20 def page(retain_content: false) if should_page? && pager = setup_pager(retain_content: retain_content) begin pid = pager.pid yield pager ensure pager.close end else yield $stdout end # When user presses Ctrl-C, IRB would raise `IRB::Abort` # But since Pager is implemented by running paging commands like `less` in another process with `IO.popen`, # the `IRB::Abort` exception only interrupts IRB's execution but doesn't affect the pager # So to properly terminate the pager with Ctrl-C, we need to catch `IRB::Abort` and kill the pager process rescue IRB::Abort begin Process.kill("TERM", pid) if pid rescue Errno::ESRCH # Pager process already terminated end nil rescue Errno::EPIPE end
page_content
(content, **options)
# File lib/irb/pager.rb, line 10 def page_content(content, **options) if content_exceeds_screen_height?(content) page(**options) do |io| io.puts content end else $stdout.puts content end end