summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConrad Irwin <conrad.irwin@gmail.com>2012-11-18 01:28:58 -0800
committerConrad Irwin <conrad.irwin@gmail.com>2012-11-18 01:29:40 -0800
commit7f4c8316e401939b7de08beae30c92bd41df4a35 (patch)
tree46366dbd5cb34e0e0663691296d779a954d448e1
parent03bf4d875dd725b08191ac6107c00b043129595a (diff)
downloadpry-7f4c8316e401939b7de08beae30c92bd41df4a35.tar.gz
Fix Indent.screen_size on jruby
-rw-r--r--lib/pry/core_extensions.rb12
-rw-r--r--lib/pry/indent.rb11
2 files changed, 6 insertions, 17 deletions
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