diff options
author | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-02-24 15:49:46 -0300 |
---|---|---|
committer | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-02-24 15:49:46 -0300 |
commit | 0dfa369c3d1673f16e3823b34ef89998307c2603 (patch) | |
tree | e7c94eb19e8c5c0470102641b54bbf391263ccaa | |
parent | 80968e9d323ae4b3456eecb5b26346a3acdeea32 (diff) | |
download | highline-0dfa369c3d1673f16e3823b34ef89998307c2603.tar.gz |
Issue #129 - Apply @elyscape suggestion
-rwxr-xr-x | lib/highline/system_extensions.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/highline/system_extensions.rb b/lib/highline/system_extensions.rb index 850b043..888d348 100755 --- a/lib/highline/system_extensions.rb +++ b/lib/highline/system_extensions.rb @@ -6,7 +6,6 @@ # This is Free Software. See LICENSE and COPYING for details. require "highline/compatibility" -require "io/console" class HighLine module SystemExtensions @@ -224,9 +223,14 @@ class HighLine # A Unix savvy method using stty to fetch the console columns, and rows. # ... stty does not work in JRuby def terminal_size - if (winsize = IO.console.winsize.reverse rescue nil) - winsize - elsif /solaris/ =~ RUBY_PLATFORM and + begin + require "io/console" + winsize = IO.console.winsize rescue nil + return winsize if winsize + rescue LoadError + end + + if /solaris/ =~ RUBY_PLATFORM and `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/ [$2, $1].map { |c| x.to_i } elsif `stty size` =~ /^(\d+)\s(\d+)$/ |