summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog5
-rw-r--r--ext/io/console/lib/console/size.rb20
2 files changed, 25 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 6f7ebddb056..222f322cf17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed May 18 22:45:26 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/io/console/lib/console/size.rb (IO#console_size): new
+ method. (EXPERIMENTAL)
+
Wed May 18 22:41:51 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* internal.h: add for internal use only.
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