module Kramdown::ANSI::Pager

def pager(command: nil, lines: nil, &block)

Returns:
  • (NilClass) - returns nil if STDOUT is used or STDOUT is not a TTY.

Other tags:
    Yield: - yields the output IO handle for further processing

Parameters:
  • lines (Integer) -- the number of lines in the output (optional)
  • command (String) -- the pager command (optional)
def pager(command: nil, lines: nil, &block)
  if block
    if my_pager = pager(command:, lines:)
      IO.popen(my_pager, 'w') do |output|
        output.sync = true
        yield output
      rescue Interrupt, Errno::EPIPE
        pager_reset_screen
        return nil
      ensure
        output.close
      end
      my_pager
    else
      yield STDOUT
      nil
    end
  else
    return unless STDOUT.tty?
    if lines
      if lines >= Tins::Terminal.lines
        pager(command:)
      end
    else
      command
    end
  end
end