summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-18 13:45:29 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-18 13:45:29 +0000
commitaef01ee7890bf6b2349c4c87548460ce9534dfb0 (patch)
tree3c1aaf8c3ba00851e106e03913ebe6c756a90211 /ext
parent52f5f410e4ce1614793328d38d55f84f66371e6e (diff)
* ext/io/console/lib/console/size.rb (IO#console_size): new
method. (EXPERIMENTAL) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/io/console/lib/console/size.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/ext/io/console/lib/console/size.rb b/ext/io/console/lib/console/size.rb
new file mode 100644
index 00000000000..e9d8a1fbb62
--- /dev/null
+++ b/ext/io/console/lib/console/size.rb
@@ -0,0 +1,20 @@
+def IO.default_console_size
+ [
+ ENV["LINES"].to_i.nonzero? || 25,
+ ENV["COLUMNS"].to_i.nonzero? || 80,
+ ]
+end
+
+begin
+ require 'io/console'
+rescue LoadError
+ class IO
+ alias console_size default_console_size
+ end
+else
+ def IO.console_size
+ console.winsize
+ rescue NoMethodError
+ default_console_size
+ end
+end