class MonoclePrint::Pager

Constants

PAGER_COMMAND

Public Class Methods

open( options = {} ) { |pager| ... } click to toggle source
# File lib/monocle-print/output-device.rb, line 485
  def self.open( options = {} )
    unless PAGER_COMMAND
      message = <<-END.gsub!( /\s+/, ' ' ).strip!
      unable to locate a pager program on the system's PATH or from
      the environmental variable, PAGER
      END
      raise( IOError, message )
    end

    options.fetch( :use_color ) { options[ :use_color ] = true }

    if block_given?
      IO.popen( PAGER_COMMAND, 'w' ) do | pager |
        pager = new( pager, options )
        return yield( pager )
      end
    else
      return new( IO.popen( PAGER_COMMAND, 'w' ), options )
    end
  end

Private Instance Methods

screen_size() click to toggle source
# File lib/monocle-print/output-device.rb, line 508
def screen_size
  @screen_size ||=
    begin
      if STDOUT.respond_to?( :winsize )
        detected_height, detected_width = STDOUT.winsize
      elsif data = SIZE_STRUCT.dup and STDOUT.ioctl( SIZE_IOCTL, data ) >= 0
        detected_height, detected_width = data.unpack( "SS" )
      else
        size = default_size
        detected_height, detected_width = size.height, size.width
      end
      Pair.new(
        @forced_height || detected_height,
        @forced_width  || detected_width
      )
    rescue Exception
      default_size
    end
end