Clean up the module-loading code in Console::Virtual.
catseye
12 years ago
0 | 0 | # Console::Virtual.pm - unbuffered-input/addressed-display layer |
1 | # v2007.1122 Chris Pressey, Cat's Eye Technologies | |
1 | # v2007.1122-YPSILAXDEV Chris Pressey, Cat's Eye Technologies | |
2 | 2 | |
3 | 3 | # Copyright (c)2003-2007, Chris Pressey, Cat's Eye Technologies. |
4 | 4 | # All rights reserved. |
47 | 47 | |
48 | 48 | BEGIN |
49 | 49 | { |
50 | my $c; | |
51 | my $fc = 0; # found Curses.pm? | |
52 | my $fs = 0; # found Term::Screen? | |
53 | my $fp = 0; # found POSIX.pm? | |
54 | my $ft = 0; # found $TERM and /etc/termcap? | |
55 | foreach $c (@INC) | |
50 | my $found_curses = 0; # found Curses.pm? | |
51 | my $found_term_screen = 0; # found Term::Screen? | |
52 | my $found_posix = 0; # found POSIX.pm? | |
53 | my $found_termcap = 0; # found $TERM and /etc/termcap? | |
54 | foreach my $path (@INC) | |
56 | 55 | { |
57 | $fc = 1 if -r "$c/Curses.pm"; | |
58 | $fs = 1 if -r "$c/Term/Screen.pm"; | |
59 | $fp = 1 if -r "$c/POSIX.pm"; | |
56 | $found_curses = 1 if -r "$path/Curses.pm"; | |
57 | $found_term_screen = 1 if -r "$path/Term/Screen.pm"; | |
58 | $found_posix = 1 if -r "$path/POSIX.pm"; | |
60 | 59 | } |
61 | $ft = $ENV{TERM} && -r "/etc/termcap"; | |
60 | $found_termcap = $ENV{TERM} && -r "/etc/termcap"; | |
62 | 61 | $| = 1; |
63 | 62 | |
64 | 63 | # Determine raw input module to use. |
67 | 66 | |
68 | 67 | if (defined $setup{input}) |
69 | 68 | { |
70 | require "Console/Input/$setup{input}.pm"; | |
71 | 69 | } |
72 | elsif ($fc) | |
70 | elsif ($found_curses) | |
73 | 71 | { |
74 | require Console::Input::Curses; | |
75 | 72 | $setup{input} = 'Curses'; |
76 | 73 | } |
77 | 74 | elsif ($^O eq 'MSWin32') |
78 | 75 | { |
79 | require Console::Input::Win32; | |
80 | 76 | $setup{input} = 'Win32'; |
81 | 77 | } |
82 | elsif ($fs) | |
78 | elsif ($found_term_screen) | |
83 | 79 | { |
84 | require Console::Input::Screen; | |
85 | 80 | $setup{input} = 'Screen'; |
86 | 81 | } |
87 | elsif ($fp) | |
82 | elsif ($found_posix) | |
88 | 83 | { |
89 | require Console::Input::POSIX; | |
90 | 84 | $setup{input} = 'POSIX'; |
91 | 85 | } else |
92 | 86 | { |
93 | 87 | warn "Warning! Raw input probably not available on this '$^O' system.\n"; |
94 | require Console::Input::Teletype; | |
95 | 88 | $setup{input} = 'Teletype'; |
96 | 89 | } |
90 | require "Console/Input/$setup{input}.pm"; | |
97 | 91 | |
98 | 92 | # Determine screen-addressed output method to use. |
99 | 93 | # This can be pre-set by the calling code |
101 | 95 | |
102 | 96 | if (defined $setup{display}) |
103 | 97 | { |
104 | require "Console/Display/$setup{display}.pm"; | |
105 | 98 | } |
106 | elsif ($fc) | |
99 | elsif ($found_curses) | |
107 | 100 | { |
108 | require Console::Display::Curses; | |
109 | 101 | $setup{display} = 'Curses'; |
110 | 102 | } |
111 | 103 | elsif ($^O eq 'MSWin32') |
112 | 104 | { |
113 | require Console::Display::Win32; | |
114 | 105 | $setup{display} = 'Win32'; |
115 | 106 | } |
116 | elsif ($fs) | |
107 | elsif ($found_term_screen) | |
117 | 108 | { |
118 | require Console::Display::Screen; | |
119 | 109 | $setup{display} = 'Screen'; |
120 | 110 | } |
121 | elsif ($ft) | |
111 | elsif ($found_termcap) | |
122 | 112 | { |
123 | require Console::Display::Tput; | |
124 | 113 | $setup{display} = 'Tput'; |
125 | 114 | } else |
126 | 115 | { |
127 | 116 | warn "Addressable screen must be emulated on this '$^O' system"; |
128 | require Console::Display::Teletype; | |
129 | 117 | $setup{display} = 'Teletype'; |
130 | 118 | } |
119 | require "Console/Display/$setup{display}.pm"; | |
131 | 120 | |
132 | 121 | # 2001.01.27 CAP |
133 | 122 | # Determine color module to use. |
136 | 125 | |
137 | 126 | if (defined $setup{color}) |
138 | 127 | { |
139 | require "Console/Color/$setup{color}.pm"; | |
140 | 128 | } |
141 | elsif ($fc) | |
129 | elsif ($found_curses) | |
142 | 130 | { |
143 | require Console::Color::Curses; | |
144 | 131 | $setup{color} = 'Curses'; |
145 | 132 | } |
146 | 133 | elsif ($^O eq 'MSWin32') |
147 | 134 | { |
148 | require Console::Color::Win32; | |
149 | 135 | $setup{color} = 'Win32'; |
150 | 136 | } |
151 | elsif ($fs) | |
137 | elsif ($found_term_screen) | |
152 | 138 | { |
153 | # require Console::Color::Screen; # TODO! needs to be written | |
154 | require Console::Color::ANSI16; # not a very general solution | |
155 | $setup{color} = 'ANSI16'; | |
139 | # $setup{color} = 'Screen'; # TODO! needs to be written | |
140 | $setup{color} = 'ANSI16'; # not a very general solution | |
156 | 141 | } |
157 | 142 | else |
158 | 143 | { |
159 | require Console::Color::Mono; | |
160 | 144 | $setup{color} = 'Mono'; |
161 | 145 | } |
146 | require "Console/Color/$setup{color}.pm"; | |
162 | 147 | } |
163 | 148 | |
164 | 149 | 1; |