From 720ef3bd208d64982ea18e89921b05524178ccb6 Mon Sep 17 00:00:00 2001 From: Piotr Murach Date: Sat, 16 Dec 2023 14:00:12 +0000 Subject: [PATCH] Fix JRuby and Windows system detection to check Ruby configuration only once --- CHANGELOG.md | 1 + lib/tty/screen.rb | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05ddb05..c0507c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * Fix to skip terminal size detection from readline on non-TTY output * Fix size detection from IO to skip loading io-console on non-TTY output * Fix size detection from tput to check for non-zero columns instead of lines +* Fix JRuby and Windows system detection to check Ruby configuration only once ## [v0.8.1] - 2020-07-17 diff --git a/lib/tty/screen.rb b/lib/tty/screen.rb index 9187ef5..201a44e 100644 --- a/lib/tty/screen.rb +++ b/lib/tty/screen.rb @@ -12,13 +12,21 @@ module TTY # # @api public module Screen + # The Ruby configuration + # + # @return [Hash] + # + # @api private + RUBY_CONFIG = defined?(::RbConfig) ? ::RbConfig::CONFIG : {} + private_constant :RUBY_CONFIG + # Helper to define private functions def self.private_module_function(name) module_function(name) private_class_method(name) end - case (defined?(::RbConfig) ? ::RbConfig::CONFIG["host_os"] : ::RUBY_PLATFORM) + case RUBY_CONFIG["host_os"] || ::RUBY_PLATFORM when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ def windows?; true end else @@ -26,7 +34,7 @@ def windows?; false end end module_function :windows? - case (defined?(::RbConfig) ? ::RbConfig::CONFIG["ruby_install_name"] : ::RUBY_ENGINE) + case RUBY_CONFIG["ruby_install_name"] || ::RUBY_ENGINE when /jruby/ def jruby?; true end else