module TTY::Pager::ClassMethods

Public Instance Methods

new(enabled: true, command: nil, **options) click to toggle source

Create a pager

@param [Boolean] :enabled

disable/enable text paging

@param [String] :command

the paging command

@param [IO] :input

the object to send input to

@param [IO] :output

the object to send output to

@param [Proc] :prompt

a proc object that accepts page number

@param [Integer] :width

the terminal width

@param [Integer] :height

the terminal height

@api public

# File lib/tty/pager.rb, line 37
def new(enabled: true, command: nil, **options)
  select_pager(enabled: enabled, command: command).new(
    enabled: enabled, command: command, **options)
end
page(text = nil, path: nil, enabled: true, command: nil, **options, &block) click to toggle source

Paginate content through null, basic or system pager.

@example

TTY::Pager.page do |pager|
  pager.write "some text"
end

@param [String] :text

an optional blob of content

@param [String] :path

a path to a file

@param [Boolean] :enabled

whether or not to use null pager

@param [String] :command

the paging command

@param [IO] :input

the object to send input to

@param [IO] :output

the object to send output to

@api public

# File lib/tty/pager.rb, line 63
def page(text = nil, path: nil, enabled: true, command: nil,
         **options, &block)
  select_pager(enabled: enabled, command: command).
    page(text, path: path, enabled: enabled, command: command,
         **options, &block)
end
select_pager(enabled: true, command: nil) click to toggle source

Select an appriopriate pager

If the user disabled paging then a NullPager is returned, otherwise a check is performed to find native system command to perform pagination with SystemPager. Finally, if no system command is found, a BasicPager is used which is a pure Ruby implementation known to work on any platform.

@param [Boolean] enabled

whether or not to allow paging

@param [String] command

the command to run if available

@api private

# File lib/tty/pager.rb, line 84
def select_pager(enabled: true, command: nil)
  commands = Array(command)

  if !enabled
    NullPager
  elsif SystemPager.exec_available?(*commands)
    SystemPager
  else
    BasicPager
  end
end