lib/tty/pager.rb in tty-pager-0.10.0 vs lib/tty/pager.rb in tty-pager-0.11.0
- old
+ new
@@ -7,10 +7,29 @@
module TTY
class Pager
Error = Class.new(StandardError)
+ # 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
+ def self.select_pager(enabled)
+ if !enabled
+ NullPager
+ elsif SystemPager.exec_available?
+ SystemPager
+ else
+ BasicPager
+ end
+ end
+
# Create a pager
#
# @param [Hash] options
# @option options [Proc] :prompt
# a proc object that accepts page number
@@ -26,11 +45,11 @@
@input = options.fetch(:input) { $stdin }
@output = options.fetch(:output) { $stdout }
@enabled = options.fetch(:enabled) { true }
if self.class == TTY::Pager
- @pager = find_available(options)
+ @pager = self.class.select_pager(@enabled).new(options)
end
end
# Check if pager is enabled
#
@@ -76,25 +95,7 @@
attr_reader :input
attr_reader :pager
- # Find available 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
- def find_available(options)
- if !enabled?
- NullPager.new
- elsif SystemPager.available?
- SystemPager.new(options)
- else
- BasicPager.new(options)
- end
- end
end # Pager
end # TTY