mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Fix Indent.screen_size on jruby
This commit is contained in:
parent
03bf4d875d
commit
7f4c8316e4
2 changed files with 6 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue