summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/io/console/lib
diff options
context:
space:
mode:
Diffstat (limited to 'jni/ruby/ext/io/console/lib')
-rw-r--r--jni/ruby/ext/io/console/lib/console/size.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/jni/ruby/ext/io/console/lib/console/size.rb b/jni/ruby/ext/io/console/lib/console/size.rb
new file mode 100644
index 0000000..519bc3b
--- /dev/null
+++ b/jni/ruby/ext/io/console/lib/console/size.rb
@@ -0,0 +1,22 @@
+# fallback to console window size
+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
+ # returns console window size
+ def IO.console_size
+ console.winsize
+ rescue NoMethodError
+ default_console_size
+ end
+end