class TTY::Pager
Constants
- Error
- VERSION
Attributes
input[R]
output[R]
pager[R]
Public Class Methods
new(**options)
click to toggle source
Create a pager
@param [Hash] options @option options [Proc] :prompt
a proc object that accepts page number
@option options [IO] :input
the object to send input to
@option options [IO] :output
the object to send output to
@option options [Boolean] :enabled
disable/enable text paging
@api public
# File lib/tty/pager.rb, line 46 def initialize(**options) @input = options.fetch(:input) { $stdin } @output = options.fetch(:output) { $stdout } @enabled = options.fetch(:enabled) { true } commands = Array(options[:command]) if self.class == TTY::Pager @pager = self.class.select_pager(@enabled, commands).new(options) end end
select_pager(enabled, commands)
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.
@api private
# File lib/tty/pager.rb, line 23 def self.select_pager(enabled, commands) if !enabled NullPager elsif SystemPager.exec_available?(*commands) SystemPager else BasicPager end end
Public Instance Methods
enabled?()
click to toggle source
Check if pager is enabled
@return [Boolean]
@api public
# File lib/tty/pager.rb, line 62 def enabled? !!@enabled end
page(text, &callback)
click to toggle source
Page the given text through the available pager
@param [String] text
the text to run through a pager
@yield [Integer] page number
@return [TTY::Pager]
@api public
# File lib/tty/pager.rb, line 76 def page(text, &callback) pager.page(text, &callback) self end
page_height()
click to toggle source
The terminal height
@api public
# File lib/tty/pager.rb, line 84 def page_height TTY::Screen.height end
page_width()
click to toggle source
The terminal width
@api public
# File lib/tty/pager.rb, line 91 def page_width TTY::Screen.width end