|
24 | 24 | require_relative 'console/version'
|
25 | 25 | require_relative 'console/common'
|
26 | 26 |
|
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 |
32 | 29 | # If Linux or BSD, try to load the native version
|
33 |
| - if RbConfig::CONFIG['host_os'].downcase =~ /darwin|openbsd|freebsd|netbsd|linux/ |
34 |
| - begin |
35 | 30 |
|
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 |
39 | 37 |
|
40 |
| - rescue Exception => ex |
| 38 | + warn "failed to load native console support: #{ex}" if $VERBOSE |
41 | 39 |
|
42 |
| - warn "failed to load native console support: #{ex}" if $VERBOSE |
43 |
| - ready = false |
| 40 | + else |
| 41 | + |
| 42 | + # Native ready. |
| 43 | + ready = true |
44 | 44 |
|
45 |
| - end |
46 | 45 | end
|
47 | 46 |
|
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 |
51 | 51 |
|
52 |
| - require_relative 'console/stty_console' |
53 |
| - ready = true |
| 52 | +end |
54 | 53 |
|
55 |
| - rescue Exception => ex2 |
| 54 | +if ready.nil? |
| 55 | + # Native is not ready, try to use stty |
56 | 56 |
|
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 |
59 | 66 |
|
60 |
| - end |
61 | 67 | end
|
| 68 | +end |
62 | 69 |
|
| 70 | +unless ready |
63 | 71 | # If still not ready, just use stubbed version
|
64 |
| - if !ready |
65 |
| - require_relative 'console/stub_console' |
66 |
| - end |
67 | 72 |
|
| 73 | + require_relative 'console/stub_console' |
68 | 74 | end
|
0 commit comments