summaryrefslogtreecommitdiff
path: root/lib/highline/terminal/unix_stty.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/highline/terminal/unix_stty.rb')
-rw-r--r--lib/highline/terminal/unix_stty.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/highline/terminal/unix_stty.rb b/lib/highline/terminal/unix_stty.rb
index 3b9668a..ad9c85d 100644
--- a/lib/highline/terminal/unix_stty.rb
+++ b/lib/highline/terminal/unix_stty.rb
@@ -5,25 +5,28 @@ class HighLine
# HighLine::Terminal option that uses external "stty" program
# to control terminal options.
class UnixStty < Terminal
-
# A Unix savvy method using stty to fetch the console columns, and rows.
# ... stty does not work in JRuby
# @return (see Terminal#terminal_size)
def terminal_size
begin
require "io/console"
- winsize = IO.console.winsize.reverse rescue nil
+ winsize = begin
+ IO.console.winsize.reverse
+ rescue NoMethodError
+ nil
+ end
return winsize if winsize
rescue LoadError
end
- if /solaris/ =~ RUBY_PLATFORM and
- `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
- [$2, $1].map { |x| x.to_i }
+ if /solaris/ =~ RUBY_PLATFORM &&
+ `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
+ [Regexp.last_match(2), Regexp.last_match(1)].map(&:to_i)
elsif `stty size` =~ /^(\d+)\s(\d+)$/
- [$2.to_i, $1.to_i]
+ [Regexp.last_match(2).to_i, Regexp.last_match(1).to_i]
else
- [ 80, 24 ]
+ [80, 24]
end
end
@@ -40,9 +43,9 @@ class HighLine
end
# (see Terminal#get_character)
- def get_character( input = STDIN )
+ def get_character(input = STDIN)
input.getc
end
end
end
-end \ No newline at end of file
+end