1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Merge pull request #687 from pry/patch/01

The SimplePager always prints to $stdout.
This commit is contained in:
Robert Gleeson 2012-08-09 14:27:39 -07:00
commit 07f7e988cf
2 changed files with 17 additions and 9 deletions

View file

@ -137,10 +137,10 @@ class Pry
if text.lines.count < Pry::Pager.page_size || !Pry.pager
out.puts text
else
Pry::Pager.page(text, out)
Pry::Pager.page(text)
end
rescue Errno::ENOENT
simple_pager(text, out)
Pry::Pager.page(text, :simple)
rescue Errno::EPIPE
end

View file

@ -3,28 +3,36 @@ class Pry::Pager
27
end
def self.page(text, out = $stdout)
is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
is_jruby ? SimplePager.new(text, out).page : SystemPager.new(text, out).page
def self.page(text, pager = nil)
case pager
when nil
is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
is_jruby ? SimplePager.new(text).page : SystemPager.new(text).page
when :simple
SimplePager.new(text).page
when :system
SystemPager.new(text).page
else
raise "'#{pager}' is not a recongized pager."
end
end
def page
raise NotImplementedError, "#{self.class} does not implement #page."
end
def initialize(text, out = $stdout)
def initialize(text)
@text = text
@out = out
end
class SimplePager < Pry::Pager
def page
text_array = @text.lines.to_a
text_array.each_slice(Pry::Pager.page_size) do |chunk|
@out.puts chunk.join
puts chunk.join
break if chunk.size < Pry::Pager.page_size
if text_array.size > Pry::Pager.page_size
@out.puts "\n<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>"
puts "\n<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>"
break if $stdin.gets.chomp == "q"
end
end