| 4 |
## |
## |
| 5 |
## $Id$ |
## $Id$ |
| 6 |
## |
## |
| 7 |
|
## $Log$ |
| 8 |
|
## Revision 1.5 2002/06/15 05:19:36 cvsjoko |
| 9 |
|
## + modified order/way of key-handling-logic |
| 10 |
|
## |
| 11 |
|
## Revision 1.4 2002/06/15 04:28:10 cvsjoko |
| 12 |
|
## immediate polling, no delay |
| 13 |
|
## |
| 14 |
|
## Revision 1.3 2002/06/15 04:24:15 cvsjoko |
| 15 |
|
## + added modifier for running in linux or win32 |
| 16 |
|
## + modified order of some commands in core key-polling |
| 17 |
|
## |
| 18 |
|
## Revision 1.2 2002/06/15 03:45:21 cvsjoko |
| 19 |
|
## + cvs id & log |
| 20 |
|
## + clearing inputbuffer just after getting the "enter"-key |
| 21 |
|
## |
| 22 |
|
## |
| 23 |
package POE::Component::Terminal; |
package POE::Component::Terminal; |
| 24 |
|
|
| 25 |
use strict; |
use strict; |
| 58 |
recieveResponse => 'recieveResponse', |
recieveResponse => 'recieveResponse', |
| 59 |
}; |
}; |
| 60 |
|
|
| 61 |
|
sub RUNNING_IN_HELL () { $^O eq 'MSWin32' } |
| 62 |
|
|
| 63 |
sub new { |
sub new { |
| 64 |
my $class = shift; |
my $class = shift; |
| 65 |
$class = ref( $class ) || $class; |
$class = ref( $class ) || $class; |
| 78 |
# store entries from args to object ($self) |
# store entries from args to object ($self) |
| 79 |
map { $self->{$_} = $args->{$_}; } keys %{$args}; |
map { $self->{$_} = $args->{$_}; } keys %{$args}; |
| 80 |
|
|
| 81 |
|
if ( RUNNING_IN_HELL () ) { |
| 82 |
|
$self->{conf}{EnterKey} = "\r"; |
| 83 |
|
} else { |
| 84 |
|
$self->{conf}{EnterKey} = "\n"; |
| 85 |
|
} |
| 86 |
|
|
| 87 |
## Make our session. See $states defined up above . . . |
## Make our session. See $states defined up above . . . |
| 88 |
POE::Session->create( object_states => [ $self => $states, ], ); |
POE::Session->create( object_states => [ $self => $states, ], ); |
| 89 |
|
|
| 197 |
} |
} |
| 198 |
|
|
| 199 |
my $key = ReadKey(-1); |
my $key = ReadKey(-1); |
| 200 |
if ($key) { |
if ( defined $key ) { |
| 201 |
|
|
|
$heap->{state}{KeyPressed} = 1; |
|
|
|
|
|
# normal key? |
|
|
if ($key =~ m/[a-zA-Z? ]/) { |
|
|
$heap->{state}{InputBuffer} .= $key; |
|
|
#print $key; |
|
|
} |
|
|
|
|
| 202 |
# enter pressed? |
# enter pressed? |
| 203 |
if ($key eq "\r") { |
if ($key eq $self->{conf}{EnterKey}) { |
| 204 |
# send command |
# send command |
| 205 |
my $buf = $heap->{state}{InputBuffer}; |
my $buf = $heap->{state}{InputBuffer}; |
| 206 |
if ($buf) { |
if ($buf) { |
| 207 |
|
$heap->{state}{InputBuffer} = ''; |
| 208 |
$heap->{state}{RequestPending} = 1; |
$heap->{state}{RequestPending} = 1; |
| 209 |
#print "ord: ", ord($buf), "\n"; |
#print "ord: ", ord($buf), "\n"; |
| 210 |
my $response_target = { |
my $response_target = { |
| 213 |
}; |
}; |
| 214 |
$kernel->post( $self->{RequestSession} => $self->{RequestState} => $buf, $response_target); |
$kernel->post( $self->{RequestSession} => $self->{RequestState} => $buf, $response_target); |
| 215 |
} |
} |
|
$heap->{state}{InputBuffer} = ''; |
|
| 216 |
|
|
| 217 |
# prepare new loop for fresh prompt |
# prepare new loop for fresh prompt |
| 218 |
print "\n"; |
print "\n"; |
| 219 |
} |
} |
| 220 |
|
|
| 221 |
# backspace pressed? |
# backspace pressed? |
| 222 |
if (ord($key) == 8) { |
elsif (ord($key) == 8) { |
| 223 |
$heap->{state}{InputBuffer} = substr($heap->{state}{InputBuffer}, 0, -1); |
$heap->{state}{InputBuffer} = substr($heap->{state}{InputBuffer}, 0, -1); |
| 224 |
} |
} |
| 225 |
|
|
| 226 |
|
# normal key? |
| 227 |
|
#elsif ($key =~ m/[a-zA-Z? ]/) { |
| 228 |
|
else { |
| 229 |
|
$heap->{state}{InputBuffer} .= $key; |
| 230 |
|
#print $key; |
| 231 |
|
} |
| 232 |
|
|
| 233 |
|
# mark "KeyPressed" for next poll |
| 234 |
|
$heap->{state}{KeyPressed} = 1; |
| 235 |
|
|
| 236 |
} |
} |
| 237 |
|
|
|
|
|
| 238 |
$kernel->post($session, "pollForKey"); |
$kernel->post($session, "pollForKey"); |
| 239 |
#$kernel->delay("term_work", 0.1); |
#$kernel->delay("pollForKey", 0.1); |
| 240 |
|
#$kernel->delay("pollForKey", 0.01); |
| 241 |
|
|
| 242 |
} |
} |
| 243 |
|
|