Class Hirb::Pager

  1. lib/hirb/pager.rb
Parent: Object

This class provides class methods for paging and an object which can conditionally page given a terminal size that is exceeded.

Methods

public class

  1. command_pager
  2. default_pager
  3. new

public instance

  1. activated_by?
  2. page

Attributes

height [R]
width [R]

Public class methods

command_pager (output, options={})

Pages using a configured or detected shell command.

[show source]
# File lib/hirb/pager.rb, line 6
      def command_pager(output, options={})
        basic_pager(output) if valid_pager_command?(options[:pager_command])
      end
default_pager (output, options={})

Pages with a ruby-only pager which either pages or quits.

[show source]
# File lib/hirb/pager.rb, line 19
      def default_pager(output, options={})
        pager = new(options[:width], options[:height])
        while pager.activated_by?(output, options[:inspect])
          puts pager.slice!(output, options[:inspect])
          return unless continue_paging?
        end
        puts output
        puts "=== Pager finished. ==="
      end
new (width, height, options={})
[show source]
# File lib/hirb/pager.rb, line 58
    def initialize(width, height, options={})
      resize(width, height)
      @pager_command = options[:pager_command] if options[:pager_command]
    end

Public instance methods

activated_by? (string_to_page, inspect_mode=false)

Determines if string should be paged based on configured width and height.

[show source]
# File lib/hirb/pager.rb, line 87
    def activated_by?(string_to_page, inspect_mode=false)
      inspect_mode ? (String.size(string_to_page) > @height * @width) : (string_to_page.count("\n") > @height)
    end
page (string, inspect_mode)

Pages given string using configured pager.

[show source]
# File lib/hirb/pager.rb, line 64
    def page(string, inspect_mode)
      if self.class.valid_pager_command?(@pager_command)
        self.class.command_pager(string, :pager_command=>@pager_command)
      else
        self.class.default_pager(string, :width=>@width, :height=>@height, :inspect=>inspect_mode)
      end
    end