|
24 | 24 | require_relative 'console/version' |
25 | 25 | require_relative 'console/common' |
26 | 26 |
|
27 | | -case RbConfig::CONFIG['host_os'] |
28 | | -when /darwin|openbsd|freebsd|netbsd|linux/i |
29 | | - # If Linux or BSD, try to load the native version |
30 | | - |
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 |
37 | | - |
38 | | - warn "failed to load native console support: #{ex}" if $VERBOSE |
39 | | - |
40 | | - else |
41 | | - |
42 | | - # Native ready. |
43 | | - ready = true |
44 | | - |
45 | | - end |
46 | | - |
| 27 | +libs = [] |
| 28 | +# If Linux or BSD, try to load the native version |
| 29 | +case RbConfig::CONFIG['host_os'].downcase |
| 30 | +when /darwin|openbsd|freebsd|netbsd/ |
| 31 | + libs << 'bsd' << 'stty' |
| 32 | +when /linux/ |
| 33 | + libs << 'linux' << 'stty' |
47 | 34 | when /mswin|win32|ming/i |
48 | 35 | # If Windows, stty is not possible, always use the stub version |
49 | | - |
50 | | - ready = false |
51 | | - |
| 36 | +else |
| 37 | + libs << 'stty' |
52 | 38 | end |
53 | 39 |
|
54 | | -if ready.nil? |
55 | | - # Native is not ready, try to use stty |
56 | | - |
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 |
66 | | - |
67 | | - end |
| 40 | +return if libs.any? do |lib| |
| 41 | + require_relative "console/#{lib}_console" |
| 42 | +rescue Exception => ex |
| 43 | + warn "failed to load #{lib} console support: #{ex}" if $VERBOSE |
| 44 | +else |
| 45 | + true |
68 | 46 | end |
69 | 47 |
|
70 | | -unless ready |
71 | | - # If still not ready, just use stubbed version |
72 | | - |
73 | | - require_relative 'console/stub_console' |
74 | | -end |
| 48 | +# If still not ready, just use stubbed version |
| 49 | +require_relative "console/stub_console" |
0 commit comments