Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 32 additions & 26 deletions lib/ffi/io/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,51 @@
require_relative 'console/version'
require_relative 'console/common'

# If Windows, always use the stub version
if RbConfig::CONFIG['host_os'] =~ /(mswin)|(win32)|(ming)/
require_relative 'console/stub_console'
else

case RbConfig::CONFIG['host_os']
when /darwin|openbsd|freebsd|netbsd|linux/i
# If Linux or BSD, try to load the native version
if RbConfig::CONFIG['host_os'].downcase =~ /darwin|openbsd|freebsd|netbsd|linux/
begin

# Attempt to load the native Linux and BSD console logic
require_relative 'console/native_console'
ready = true
begin

# Attempt to load the native Linux and BSD console logic
require_relative 'console/native_console'

rescue Exception => ex

rescue Exception => ex
warn "failed to load native console support: #{ex}" if $VERBOSE

warn "failed to load native console support: #{ex}" if $VERBOSE
ready = false
else

# Native ready.
ready = true

end
end

# Native failed, try to use stty
if !ready
begin
when /mswin|win32|ming/i
# If Windows, stty is not possible, always use the stub version

ready = false

require_relative 'console/stty_console'
ready = true
end

rescue Exception => ex2
if ready.nil?
# Native is not ready, try to use stty

warn "failed to load stty console support: #{ex2}" if $VERBOSE
ready = false
begin

require_relative 'console/stty_console'
ready = true

rescue Exception => ex2

warn "failed to load stty console support: #{ex2}" if $VERBOSE
ready = false

end
end
end

unless ready
# If still not ready, just use stubbed version
if !ready
require_relative 'console/stub_console'
end

require_relative 'console/stub_console'
end
Loading