diff --git a/lib/pry/core_extensions.rb b/lib/pry/core_extensions.rb index 88acd17f..608e100d 100644 --- a/lib/pry/core_extensions.rb +++ b/lib/pry/core_extensions.rb @@ -119,15 +119,3 @@ if [[1, 2]].pretty_inspect == "[1]\n" end end end - -if defined?(JRUBY_VERSION) && JRUBY_VERSION == "1.7.0" - require 'io/console' - class IO - def winsize - stty_info = `stty -a` - match = stty_info.match(/(\d+) rows; (\d+) columns/) # BSD version of stty, like the one used in Mac OS X - match ||= stty_info.match(/; rows (\d+); columns (\d+)/) # GNU version of stty, like the one used in Ubuntu - [match[1].to_i, match[2].to_i] - end - end -end diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb index 1e9a08fb..5d74a453 100644 --- a/lib/pry/indent.rb +++ b/lib/pry/indent.rb @@ -410,20 +410,21 @@ class Pry # If the window size cannot be determined, return nil. def screen_size [ - # io/console adds a winsize method to IO streams. - $stdout.tty? && $stdout.respond_to?(:winsize) && $stdout.winsize, - # Some readlines also provides get_screen_size. + # Readline comes before IO#winsize because jruby sometimes defaults winsize to [25, 80] Readline.respond_to?(:get_screen_size) && Readline.get_screen_size, + # io/console adds a winsize method to IO streams. + # rescue nil for jruby 1.7.0 [jruby/jruby#354] + $stdout.tty? && $stdout.respond_to?(:winsize) && ($stdout.winsize rescue nil), + # Otherwise try to use the environment (this may be out of date due # to window resizing, but it's better than nothing). - [ENV["ROWS"], ENV["COLUMNS"], + [ENV["ROWS"], ENV["COLUMNS"]], # If the user is running within ansicon, then use the screen size # that it reports (same caveats apply as with ROWS and COLUMNS) ENV['ANSICON'] =~ /\((.*)x(.*)\)/ && [$2, $1] - ] ].detect do |(_, cols)| cols.to_i > 0 end