class Pry::Pager::SystemPager - pry-0.10.1 Documentation

# class Pry::Pager::SystemPager

`SystemPager` buffers output until we’re pretty sure it’s at least a page long, then invokes an external pager and starts streaming output to it. If `#close` is called before then, it just prints out the buffered content.

### Public Class Methods

available?() click to toggle source

    # File lib/pry/pager.rb, line 136
    def self.available?
      if @system_pager.nil?
        @system_pager = begin
          pager_executable = default_pager.split(' ').first
          %x`which #{pager_executable}`
          $?.success?
        rescue
          false
        end
      else
        @system_pager
      end
    end

default_pager() click to toggle source

    # File lib/pry/pager.rb, line 125
    def self.default_pager
      pager = ENV["PAGER"] || ""

      # Default to less, and make sure less is being passed the correct options
      if pager.strip.empty? or pager =~ /^less\b/
        pager = "less -R -F -X"
      end

      pager
    end

new(*) click to toggle source
Calls superclass method Pry::Pager::NullPager.new

    # File lib/pry/pager.rb, line 150
    def initialize(*)
      super
      @tracker = PageTracker.new(height, width)
      @buffer  = ""
    end

### Public Instance Methods

close() click to toggle source

    # File lib/pry/pager.rb, line 171
    def close
      if invoked_pager?
        pager.close
      else
        @out.puts @buffer
      end
    end

write(str) click to toggle source

    # File lib/pry/pager.rb, line 156
    def write(str)
      if invoked_pager?
        write_to_pager str
      else
        @tracker.record str
        @buffer << str

        if @tracker.page?
          write_to_pager @buffer
        end
      end
    rescue Errno::EPIPE
      raise StopPaging
    end