5 |
## $Id$ |
## $Id$ |
6 |
## |
## |
7 |
## $Log$ |
## $Log$ |
8 |
|
## Revision 1.7 2002/06/15 07:56:40 cvsjoko |
9 |
|
## + bugfixes for win32 (additional keys) |
10 |
|
## |
11 |
|
## Revision 1.6 2002/06/15 07:46:11 cvsjoko |
12 |
|
## + bugfixes for linux |
13 |
|
## |
14 |
|
## Revision 1.5 2002/06/15 05:19:36 cvsjoko |
15 |
|
## + modified order/way of key-handling-logic |
16 |
|
## |
17 |
## Revision 1.4 2002/06/15 04:28:10 cvsjoko |
## Revision 1.4 2002/06/15 04:28:10 cvsjoko |
18 |
## immediate polling, no delay |
## immediate polling, no delay |
19 |
## |
## |
85 |
map { $self->{$_} = $args->{$_}; } keys %{$args}; |
map { $self->{$_} = $args->{$_}; } keys %{$args}; |
86 |
|
|
87 |
if ( RUNNING_IN_HELL () ) { |
if ( RUNNING_IN_HELL () ) { |
88 |
$self->{conf}{EnterKey} = "\r"; |
$self->{conf}{KeyEnter} = 13; |
89 |
|
$self->{conf}{KeyBackspace} = 8; |
90 |
|
$self->{conf}{KeyCTRLC} = 3; |
91 |
} else { |
} else { |
92 |
$self->{conf}{EnterKey} = "\n"; |
$self->{conf}{KeyEnter} = 10; |
93 |
|
$self->{conf}{KeyBackspace} = 127; |
94 |
|
$self->{conf}{KeyCTRLC} = 3; |
95 |
} |
} |
96 |
|
|
97 |
## Make our session. See $states defined up above . . . |
## Make our session. See $states defined up above . . . |
119 |
$heap->{state}{InputBuffer} = ''; |
$heap->{state}{InputBuffer} = ''; |
120 |
$heap->{state}{Startup} = 1; |
$heap->{state}{Startup} = 1; |
121 |
$heap->{state}{Caption} = $self->{Caption}; |
$heap->{state}{Caption} = $self->{Caption}; |
122 |
|
$heap->{state}{KeyPressed} = 0; |
123 |
|
$heap->{state}{RequestPending} = 0; |
124 |
|
|
125 |
# initially call worker-state |
# initially call worker-state |
126 |
|
ReadMode 4; |
127 |
$kernel->post($session, "pollForKey"); |
$kernel->post($session, "pollForKey"); |
128 |
|
|
129 |
return; |
return; |
197 |
my $prompt = "#> "; |
my $prompt = "#> "; |
198 |
$prompt = $self->{PromptPrefix} . ' ' . $prompt_inlay . $self->{PromptPostfix}; |
$prompt = $self->{PromptPrefix} . ' ' . $prompt_inlay . $self->{PromptPostfix}; |
199 |
|
|
200 |
if ( ($heap->{state}{KeyPressed} && !$heap->{state}{RequestPending}) || ($heap->{state}{Startup}) ) { |
if ( ( |
201 |
|
( $heap->{state}{KeyPressed} == 1 ) && |
202 |
|
( $heap->{state}{RequestPending} == 0 ) |
203 |
|
) || |
204 |
|
( $heap->{state}{Startup} ) |
205 |
|
) { |
206 |
$heap->{state}{Startup} = 0; |
$heap->{state}{Startup} = 0; |
207 |
$heap->{state}{KeyPressed} = 0; |
$heap->{state}{KeyPressed} = 0; |
|
#ReadMode 4; # Turn off controls keys |
|
|
#ReadMode 1; |
|
|
#print $prompt; |
|
208 |
my $outputline = $prompt . $heap->{state}{InputBuffer}; |
my $outputline = $prompt . $heap->{state}{InputBuffer}; |
209 |
my $s = ' ' x (length($outputline) + 1); |
my $s = ' ' x (length($outputline) + 1); |
210 |
print "\r", $s; |
print "\r", $s; |
211 |
print "\r", $outputline; |
print "\r", $outputline; |
212 |
|
#print $outputline; |
213 |
} |
} |
214 |
|
|
215 |
my $key = ReadKey(-1); |
my $key = ReadKey(-1); |
216 |
if ($key) { |
if ( defined $key ) { |
217 |
|
|
218 |
|
#print "key: ", ord($key), "\n"; |
219 |
|
|
220 |
# normal key? |
# CTRL+C pressed? |
221 |
if ($key =~ m/[a-zA-Z? ]/) { |
if (ord($key) == $self->{conf}{KeyCTRLC}) { |
222 |
$heap->{state}{InputBuffer} .= $key; |
ReadMode 1; |
223 |
#print $key; |
print "\n"; |
224 |
|
exit; |
225 |
} |
} |
226 |
|
|
227 |
# enter pressed? |
# enter pressed? |
228 |
if ($key eq $self->{conf}{EnterKey}) { |
if (ord($key) == $self->{conf}{KeyEnter}) { |
229 |
# send command |
|
230 |
|
# if enter was pressed while request was pending, |
231 |
|
# we should stop waiting for output and come back to prompt again, |
232 |
|
if ($heap->{state}{RequestPending}) { |
233 |
|
$kernel->post( $self->{ResponseSession} => $self->{ResponseState} => ' < stopped waiting for response'); |
234 |
|
} |
235 |
|
|
236 |
|
# send command, if buffer is filled |
237 |
my $buf = $heap->{state}{InputBuffer}; |
my $buf = $heap->{state}{InputBuffer}; |
238 |
if ($buf) { |
if ($buf) { |
239 |
$heap->{state}{InputBuffer} = ''; |
$heap->{state}{InputBuffer} = ''; |
240 |
$heap->{state}{RequestPending} = 1; |
$heap->{state}{RequestPending} = 1; |
|
#print "ord: ", ord($buf), "\n"; |
|
241 |
my $response_target = { |
my $response_target = { |
242 |
ResponseSession => $self->{ResponseSession}, |
ResponseSession => $self->{ResponseSession}, |
243 |
ResponseState => $self->{ResponseState}, |
ResponseState => $self->{ResponseState}, |
247 |
|
|
248 |
# prepare new loop for fresh prompt |
# prepare new loop for fresh prompt |
249 |
print "\n"; |
print "\n"; |
250 |
|
|
251 |
} |
} |
252 |
|
|
253 |
# backspace pressed? |
# backspace pressed? |
254 |
if (ord($key) == 8) { |
elsif (ord($key) == $self->{conf}{KeyBackspace}) { |
255 |
$heap->{state}{InputBuffer} = substr($heap->{state}{InputBuffer}, 0, -1); |
$heap->{state}{InputBuffer} = substr($heap->{state}{InputBuffer}, 0, -1); |
256 |
} |
} |
257 |
|
|
258 |
|
# normal key? |
259 |
|
#elsif ($key =~ m/[a-zA-Z? ]/) { |
260 |
|
else { |
261 |
|
$heap->{state}{InputBuffer} .= $key; |
262 |
|
#print $key; |
263 |
|
} |
264 |
|
|
265 |
# mark "KeyPressed" for next poll |
# mark "KeyPressed" for next poll |
266 |
$heap->{state}{KeyPressed} = 1; |
$heap->{state}{KeyPressed} = 1; |
267 |
|
|
268 |
} |
} |
269 |
|
|
270 |
$kernel->post($session, "pollForKey"); |
#$kernel->post($session, "pollForKey"); |
271 |
|
#$kernel->run_one_timeslice(); |
272 |
|
#$kernel->post($session, "pollForKey"); |
273 |
|
#$kernel->yield($session, "pollForKey"); |
274 |
#$kernel->delay("pollForKey", 0.1); |
#$kernel->delay("pollForKey", 0.1); |
275 |
#$kernel->delay("pollForKey", 0.01); |
$kernel->delay("pollForKey", 0.001); |
276 |
|
|
277 |
} |
} |
278 |
|
|
281 |
|
|
282 |
sub recieveResponse { |
sub recieveResponse { |
283 |
my ($kernel, $heap, $session, $response) = @_[KERNEL, HEAP, SESSION, ARG0]; |
my ($kernel, $heap, $session, $response) = @_[KERNEL, HEAP, SESSION, ARG0]; |
284 |
if ($response) { print $response, "\n"; } |
if ($response) { |
285 |
$heap->{state}{RequestPending} = 0; |
print $response, "\n"; |
286 |
|
$heap->{state}{RequestPending} = 0; |
287 |
|
} |
288 |
} |
} |
289 |
sub recievePrompt { |
sub recievePrompt { |
290 |
my ($kernel, $heap, $session, $prompt_inlay) = @_[KERNEL, HEAP, SESSION, ARG0]; |
my ($kernel, $heap, $session, $prompt_inlay) = @_[KERNEL, HEAP, SESSION, ARG0]; |