Permalink
Browse files

Adding support for finding the terminal size on Solaris.

  • Loading branch information...
1 parent bae3b66 commit 4a0c3097f921612f78a16d13b805da06971a47e2 @JEG2 committed Aug 7, 2007
Showing with 16 additions and 6 deletions.
  1. +5 −0 highline/CHANGELOG
  2. +1 −1 highline/lib/highline.rb
  3. +10 −5 highline/lib/highline/system_extensions.rb
View
@@ -2,6 +2,11 @@
Below is a complete listing of changes for each revision of HighLine.
+== 1.4.0
+
+* Made the code grabbing terminal size a little more cross-platform by
+ adding support for Solaris. (patch by Ronald Braswell and Coey Minear)
+
== 1.2.9
* Additional work on the backspacing issue. (patch by Jeremy Hinegardner)
View
@@ -29,7 +29,7 @@
#
class HighLine
# The version of the installed library.
- VERSION = "1.2.9".freeze
+ VERSION = "1.4.0".freeze
# An internal HighLine error. User code does not need to trap this.
class QuestionError < StandardError
@@ -20,7 +20,7 @@ module SystemExtensions
# Cygwin will look like Windows, but we want to treat it like a Posix OS:
raise LoadError, "Cygwin is a Posix OS." if RUBY_PLATFORM =~ /\bcygwin\b/i
- require "Win32API" # See if we're on Windows.
+ require "Win32API" # See if we're on Windows.
CHARACTER_MODE = "Win32API" # For Debugging purposes only.
@@ -53,9 +53,9 @@ def terminal_size
left, top, right, bottom, maxx, maxy = buf.unpack(format)
return right - left + 1, bottom - top + 1
end
- rescue LoadError # If we're not on Windows try...
+ rescue LoadError # If we're not on Windows try...
begin
- require "termios" # Unix, first choice.
+ require "termios" # Unix, first choice.
CHARACTER_MODE = "termios" # For Debugging purposes only.
@@ -78,7 +78,7 @@ def get_character( input = STDIN )
Termios.setattr(input, Termios::TCSANOW, old_settings)
end
end
- rescue LoadError # If our first choice fails, default.
+ rescue LoadError # If our first choice fails, default.
CHARACTER_MODE = "stty" # For Debugging purposes only.
#
@@ -118,7 +118,12 @@ def restore_mode
# A Unix savvy method to fetch the console columns, and rows.
def terminal_size
- `stty size`.split.map { |x| x.to_i }.reverse
+ if /solaris/ =~ RUBY_PLATFORM and
+ `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/
+ [$2, $1].map { |c| x.to_i }
+ else
+ `stty size`.split.map { |x| x.to_i }.reverse
+ end
end
end
end

0 comments on commit 4a0c309

Please sign in to comment.