Skip to content

Commit 431c3f3

Browse files
committed
Reorder dispatching by host_os
The stub version might be used on macOS in 2032.
1 parent 9882419 commit 431c3f3

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

lib/ffi/io/console.rb

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,51 @@
2424
require_relative 'console/version'
2525
require_relative 'console/common'
2626

27-
# If Windows, always use the stub version
28-
if RbConfig::CONFIG['host_os'] =~ /(mswin)|(win32)|(ming)/
29-
require_relative 'console/stub_console'
30-
else
31-
27+
case RbConfig::CONFIG['host_os']
28+
when /darwin|openbsd|freebsd|netbsd|linux/i
3229
# If Linux or BSD, try to load the native version
33-
if RbConfig::CONFIG['host_os'].downcase =~ /darwin|openbsd|freebsd|netbsd|linux/
34-
begin
3530

36-
# Attempt to load the native Linux and BSD console logic
37-
require_relative 'console/native_console'
38-
ready = true
31+
begin
32+
33+
# Attempt to load the native Linux and BSD console logic
34+
require_relative 'console/native_console'
35+
36+
rescue Exception => ex
3937

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

42-
warn "failed to load native console support: #{ex}" if $VERBOSE
43-
ready = false
40+
else
41+
42+
# Native ready.
43+
ready = true
4444

45-
end
4645
end
4746

48-
# Native failed, try to use stty
49-
if !ready
50-
begin
47+
when /mswin|win32|ming/i
48+
# If Windows, stty is not possible, always use the stub version
49+
50+
ready = false
5151

52-
require_relative 'console/stty_console'
53-
ready = true
52+
end
5453

55-
rescue Exception => ex2
54+
if ready.nil?
55+
# Native is not ready, try to use stty
5656

57-
warn "failed to load stty console support: #{ex2}" if $VERBOSE
58-
ready = false
57+
begin
58+
59+
require_relative 'console/stty_console'
60+
ready = true
61+
62+
rescue Exception => ex2
63+
64+
warn "failed to load stty console support: #{ex2}" if $VERBOSE
65+
ready = false
5966

60-
end
6167
end
68+
end
6269

70+
unless ready
6371
# If still not ready, just use stubbed version
64-
if !ready
65-
require_relative 'console/stub_console'
66-
end
6772

73+
require_relative 'console/stub_console'
6874
end

0 commit comments

Comments
 (0)