Move the pager to Pry::Pager.
This commit is contained in:
parent
6386706645
commit
f84e65bf04
|
@ -216,3 +216,4 @@ require "pry/core_extensions"
|
|||
require "pry/pry_class"
|
||||
require "pry/pry_instance"
|
||||
require "pry/cli"
|
||||
require "pry/pager"
|
||||
|
|
|
@ -91,10 +91,6 @@ class Pry
|
|||
Pry.color ? "\e[1m#{text}\e[0m": text
|
||||
end
|
||||
|
||||
def page_size
|
||||
27
|
||||
end
|
||||
|
||||
# have fun on the Windows platform.
|
||||
def windows?
|
||||
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
||||
|
@ -123,22 +119,8 @@ class Pry
|
|||
RUBY_VERSION =~ /1.9/ && RbConfig::CONFIG['ruby_install_name'] == 'ruby'
|
||||
end
|
||||
|
||||
# a simple pager for systems without `less`. A la windows.
|
||||
def simple_pager(text, output=output())
|
||||
text_array = text.lines.to_a
|
||||
text_array.each_slice(page_size) do |chunk|
|
||||
output.puts chunk.join
|
||||
break if chunk.size < page_size
|
||||
if text_array.size > page_size
|
||||
output.puts "\n<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>"
|
||||
break if $stdin.gets.chomp == "q"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Try to use `less` for paging, if it fails then use
|
||||
# simple_pager. Also do not page if Pry.pager is falsey
|
||||
# FIXME! Another JRuby hack
|
||||
def stagger_output(text, out = nil)
|
||||
out ||= case
|
||||
when respond_to?(:output)
|
||||
|
@ -152,17 +134,17 @@ class Pry
|
|||
$stdout
|
||||
end
|
||||
|
||||
if text.lines.count < page_size || !Pry.pager
|
||||
out.puts text
|
||||
return
|
||||
end
|
||||
#if text.lines.count < Pry::Pager.page_size || !Pry.pager
|
||||
# out.puts text
|
||||
# return
|
||||
#end
|
||||
|
||||
# FIXME! Another JRuby hack
|
||||
if jruby?
|
||||
simple_pager(text, out)
|
||||
else
|
||||
lesspipe { |less| less.puts text }
|
||||
end
|
||||
|
||||
Pry::Pager.new(text, out).page
|
||||
#else
|
||||
# lesspipe { |less| less.puts text }
|
||||
#end
|
||||
rescue Errno::ENOENT
|
||||
simple_pager(text, out)
|
||||
rescue Errno::EPIPE
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
class Pry::Pager
|
||||
def self.page_size
|
||||
27
|
||||
end
|
||||
|
||||
def initialize(text, io)
|
||||
@text = text
|
||||
@out = io
|
||||
end
|
||||
|
||||
def page
|
||||
text_array = @text.lines.to_a
|
||||
text_array.each_slice(Pry::Pager.page_size) do |chunk|
|
||||
@out.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>"
|
||||
break if $stdin.gets.chomp == "q"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue