Class: Pry::Pager
Defined Under Namespace
Classes: NullPager, PageTracker, SimplePager, StopPaging, SystemPager
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
private
Returns the value of attribute output.
-
#pry_instance ⇒ Object
readonly
Returns the value of attribute pry_instance.
Instance Method Summary collapse
-
#best_available ⇒ Object
private
Return an instance of the "best" available pager class --
SystemPager
if possible,SimplePager
ifSystemPager
isn't available, andNullPager
if the user has disabled paging. - #enabled? ⇒ Boolean private
-
#initialize(pry_instance) ⇒ Pager
constructor
A new instance of Pager.
-
#open ⇒ Object
Yields a pager object (
NullPager
,SimplePager
, orSystemPager
). -
#page(text) ⇒ Object
Send the given text through the best available pager (if
Pry.config.pager
is enabled).
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
#output ⇒ Object (readonly, private)
Returns the value of attribute output.
47 48 49 |
# File 'lib/pry/pager.rb', line 47 def output @output end |
#pry_instance ⇒ Object (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_available ⇒ Object (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)
43 44 45 |
# File 'lib/pry/pager.rb', line 43 def enabled? !!@enabled end |
#open ⇒ Object
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.
25 26 27 28 29 |
# File 'lib/pry/pager.rb', line 25 def page(text) open do |pager| pager << text end end |