Skip to content

Commit

Permalink
Respect $PAGER (shell environment variable).
Browse files Browse the repository at this point in the history
Closes pry#736.
  • Loading branch information
Rob Gleeson committed Oct 26, 2012
1 parent c4074b3 commit 602b567
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/pry/pager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Pry::Pager
def self.page(text, pager = nil)
case pager
when nil
no_pager = !(`less` rescue nil)
no_pager = !SystemPager.available?
is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
(is_jruby || no_pager) ? SimplePager.new(text).page : SystemPager.new(text).page
when :simple
Expand Down Expand Up @@ -54,9 +54,22 @@ def page
end

class SystemPager < Pry::Pager
def self.default_pager
ENV["PAGER"] || "less -R -S -F -X"
end

def self.available?
`#{default_pager}`rescue nil
end

def initialize(*)
super
@pager = ENV["PAGER"] || "less -R -S -F -X"
end

def page
IO.popen("less -R -S -F -X", "w") do |less|
less.puts @text
IO.popen(@pager, 'w') do |io|
io.write @text
end
end
end
Expand Down

0 comments on commit 602b567

Please sign in to comment.