Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move the pager to Pry::Pager.

  • Loading branch information...
commit f84e65bf04d6e457f72d17d2ff6d94bf14404b06 1 parent 6386706
@strcmp strcmp authored
Showing with 32 additions and 27 deletions.
  1. +1 −0  lib/pry.rb
  2. +9 −27 lib/pry/helpers/base_helpers.rb
  3. +22 −0 lib/pry/pager.rb
View
1  lib/pry.rb
@@ -216,3 +216,4 @@ module ExtendCommandBundle
require "pry/pry_class"
require "pry/pry_instance"
require "pry/cli"
+require "pry/pager"
View
36 lib/pry/helpers/base_helpers.rb
@@ -91,10 +91,6 @@ def heading(text)
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 @@ def mri_19?
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 @@ def stagger_output(text, out = nil)
$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
View
22 lib/pry/pager.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.