class Hirb::Pager

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

Attributes

height[R]
options[R]
width[R]

Public Class Methods

basic_pager(output, override_pager_command=nil) click to toggle source
# File lib/spirit_hands/hirb/fixes/pager.rb, line 19
def basic_pager(output, override_pager_command=nil)
  pc = basic_pager_command(override_pager_command)
  pager = IO.popen(pc, "w")
  begin
    save_stdout = STDOUT.clone
    STDOUT.reopen(pager)
    STDOUT.puts output
  rescue Errno::EPIPE
  ensure
   STDOUT.reopen(save_stdout)
   save_stdout.close
   pager.close
  end
end
command_pager(output, options={}) click to toggle source
# File lib/spirit_hands/hirb/fixes/pager.rb, line 11
def command_pager(output, options={})
  if valid_pager_command?(pc = options[:pager_command])
    basic_pager(output, pc)
  end
end
default_pager(output, options={}) click to toggle source
# File lib/spirit_hands/hirb/fixes/pager.rb, line 45
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={}) click to toggle source
# File lib/spirit_hands/hirb/fixes/pager.rb, line 105
def initialize(width, height, options={})
  resize(width, height)
  @options = options
end
page(string, inspect_mode, pgr_cmd, width, height) click to toggle source
# File lib/spirit_hands/hirb/fixes/pager.rb, line 55
def page(string, inspect_mode, pgr_cmd, width, height)
  if valid_pager_command?(pgr_cmd)
    command_pager(string, :pager_command=>pgr_cmd)
  else
    default_pager(string, :width=>width, :height=>height, :inspect=>inspect_mode)
  end
end

Public Instance Methods

activated_by?(string_to_page, inspect_mode=false) click to toggle source
# File lib/spirit_hands/hirb/fixes/pager.rb, line 137
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) click to toggle source
# File lib/spirit_hands/hirb/fixes/pager.rb, line 116
def page(string, inspect_mode)
  self.class.page(string, inspect_mode, pager_command, @width, @height)
end
pager_command() click to toggle source
# File lib/spirit_hands/hirb/fixes/pager.rb, line 110
def pager_command
  options[:pager_command] || self.class.pager_command
end