Class: Pry::Pager::SystemPager

Inherits:
NullPager show all
Defined in:
lib/pry/pager.rb

Overview

`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.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NullPager

#print, #puts

Constructor Details

#initializeSystemPager

Returns a new instance of SystemPager.


150
151
152
153
154
# File 'lib/pry/pager.rb', line 150

def initialize(*)
  super
  @tracker = PageTracker.new(height, width)
  @buffer  = ""
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)

136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/pry/pager.rb', line 136

def self.available?
  if @system_pager.nil?
    @system_pager = begin
      pager_executable = default_pager.split(' ').first
      `which #{pager_executable}`
      $?.success?
    rescue
      false
    end
  else
    @system_pager
  end
end

.default_pagerObject


125
126
127
128
129
130
131
132
133
134
# 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

Instance Method Details

#closeObject


171
172
173
174
175
176
177
# File 'lib/pry/pager.rb', line 171

def close
  if invoked_pager?
    pager.close
  else
    @out.puts @buffer
  end
end

#write(str) ⇒ Object


156
157
158
159
160
161
162
163
164
165
166
167
168
169
# 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