Class: Pry::Pager

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

Defined Under Namespace

Classes: NullPager, PageTracker, SimplePager, StopPaging, SystemPager

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pry_instance) ⇒ Pager

Returns a new instance of Pager.



13
14
15
# File 'lib/pry/pager.rb', line 13

def initialize(pry_instance)
  @pry_instance = pry_instance
end

Instance Attribute Details

#outputObject (readonly, private)

Returns the value of attribute output.



47
48
49
# File 'lib/pry/pager.rb', line 47

def output
  @output
end

#pry_instanceObject (readonly)

Returns the value of attribute pry_instance.



11
12
13
# File 'lib/pry/pager.rb', line 11

def pry_instance
  @pry_instance
end

Instance Method Details

#best_availableObject (private)

Return an instance of the "best" available pager class -- SystemPager if possible, SimplePager if SystemPager isn't available, and NullPager if the user has disabled paging. All pagers accept output with #puts, #print, #write, and #<<. You must call #close when you're done writing output to a pager, and you must rescue Pry::Pager::StopPaging. These requirements can be avoided by using .open instead.



56
57
58
59
60
61
62
63
64
# File 'lib/pry/pager.rb', line 56

def best_available
  if !pry_instance.config.pager
    NullPager.new(pry_instance.output)
  elsif !SystemPager.available? || Helpers::Platform.jruby?
    SimplePager.new(pry_instance.output)
  else
    SystemPager.new(pry_instance.output)
  end
end

#enabled?Boolean (private)

Returns:

  • (Boolean)


43
44
45
# File 'lib/pry/pager.rb', line 43

def enabled?
  !!@enabled
end

#openObject

Yields a pager object (NullPager, SimplePager, or SystemPager). All pagers accept output with #puts, #print, #write, and #<<.



33
34
35
36
37
38
39
# File 'lib/pry/pager.rb', line 33

def open
  pager = best_available
  yield pager
rescue StopPaging # rubocop:disable Lint/HandleExceptions
ensure
  pager.close if pager
end

#page(text) ⇒ Object

Send the given text through the best available pager (if Pry.config.pager is enabled). If you want to send text through in chunks as you generate it, use open to get a writable object instead.

Parameters:

  • text (String)

    Text to run through a pager.



25
26
27
28
29
# File 'lib/pry/pager.rb', line 25

def page(text)
  open do |pager|
    pager << text
  end
end