mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Ensure TerminalInfo.screen_size returns numbers safely
This commit is contained in:
parent
6a9dd8ee70
commit
408fdb98d2
1 changed files with 11 additions and 2 deletions
|
@ -3,6 +3,15 @@ class Pry::TerminalInfo
|
|||
#
|
||||
# If the window size cannot be determined, return nil.
|
||||
def self.screen_size
|
||||
rows, cols = actual_screen_size
|
||||
if rows && cols
|
||||
[rows.to_i, cols.to_i]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.actual_screen_size
|
||||
[
|
||||
# Some readlines also provides get_screen_size.
|
||||
# Readline comes before IO#winsize because jruby sometimes defaults winsize to [25, 80]
|
||||
|
@ -18,9 +27,9 @@ class Pry::TerminalInfo
|
|||
|
||||
# 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]
|
||||
ENV['ANSICON'] =~ /\((.*)x(.*)\)/ && [$2, $1],
|
||||
].detect do |(_, cols)|
|
||||
cols.to_i > 0
|
||||
end.map!(&:to_i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue