summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/io/console/lib
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/ext/io/console/lib
Fresh start
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