lib/tty/pager.rb in tty-pager-0.7.1 vs lib/tty/pager.rb in tty-pager-0.8.0

- old
+ new

@@ -7,57 +7,35 @@ require_relative "pager/system" require_relative "pager/version" module TTY class Pager - PROMPT_HEIGHT = 2 + Error = Class.new(StandardError) - PAGE_BREAK = "\n--- Page -%s- " \ - "Press enter/return to continue " \ - "(or q to quit) ---".freeze - # 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 [Integer] :height - # the terminal height - # @option options [Integer] :width - # the terminal width # @option options [Boolean] :enabled # disable/enable text paging # # @api public def initialize(options = {}) - @height = options.fetch(:height) { page_height } - @width = options.fetch(:width) { page_width } @input = options.fetch(:input) { $stdin } @output = options.fetch(:output) { $stdout } @enabled = options.fetch(:enabled) { true } - @prompt = options.fetch(:prompt) { default_prompt } - @height -= PROMPT_HEIGHT - @output = output if self.class == TTY::Pager - @pager = find_available + @pager = find_available(options) end end - # Default prompt for paging - # - # @return [Proc] - # - # @api private - def default_prompt - proc { |page_num| output.puts PAGE_BREAK % page_num } - end - # Check if pager is enabled # # @return [Boolean] # # @api public @@ -109,16 +87,16 @@ # utility to perform pagination with SystemPager. Finally, # if no system utility exists a BasicPager is used which # is pure Ruby implementation. # # @api private - def find_available + def find_available(options) if !enabled? NullPager.new - elsif SystemPager.available? && !Pager.jruby? - SystemPager.new + elsif !Pager.jruby? && SystemPager.can? + SystemPager.new(options) else - BasicPager.new + BasicPager.new(options) end end # Check if running on jruby #