Skip to content

Commit

Permalink
Fix JRuby and Windows system detection to check Ruby configuration on…
Browse files Browse the repository at this point in the history
…ly once
  • Loading branch information
piotrmurach committed Dec 16, 2023
1 parent 22ace3b commit 720ef3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions lib/tty/screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@ 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
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
Expand Down

0 comments on commit 720ef3b

Please sign in to comment.