| 4 |
## |
## |
| 5 |
## $Id$ |
## $Id$ |
| 6 |
## |
## |
| 7 |
|
## $Log$ |
| 8 |
|
## Revision 1.3 2002/06/15 04:24:15 cvsjoko |
| 9 |
|
## + added modifier for running in linux or win32 |
| 10 |
|
## + modified order of some commands in core key-polling |
| 11 |
|
## |
| 12 |
|
## Revision 1.2 2002/06/15 03:45:21 cvsjoko |
| 13 |
|
## + cvs id & log |
| 14 |
|
## + clearing inputbuffer just after getting the "enter"-key |
| 15 |
|
## |
| 16 |
|
## |
| 17 |
package POE::Component::Terminal; |
package POE::Component::Terminal; |
| 18 |
|
|
| 19 |
use strict; |
use strict; |
| 52 |
recieveResponse => 'recieveResponse', |
recieveResponse => 'recieveResponse', |
| 53 |
}; |
}; |
| 54 |
|
|
| 55 |
|
sub RUNNING_IN_HELL () { $^O eq 'MSWin32' } |
| 56 |
|
|
| 57 |
sub new { |
sub new { |
| 58 |
my $class = shift; |
my $class = shift; |
| 59 |
$class = ref( $class ) || $class; |
$class = ref( $class ) || $class; |
| 72 |
# store entries from args to object ($self) |
# store entries from args to object ($self) |
| 73 |
map { $self->{$_} = $args->{$_}; } keys %{$args}; |
map { $self->{$_} = $args->{$_}; } keys %{$args}; |
| 74 |
|
|
| 75 |
|
if ( RUNNING_IN_HELL () ) { |
| 76 |
|
$self->{conf}{EnterKey} = "\r"; |
| 77 |
|
} else { |
| 78 |
|
$self->{conf}{EnterKey} = "\n"; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
## Make our session. See $states defined up above . . . |
## Make our session. See $states defined up above . . . |
| 82 |
POE::Session->create( object_states => [ $self => $states, ], ); |
POE::Session->create( object_states => [ $self => $states, ], ); |
| 83 |
|
|
| 193 |
my $key = ReadKey(-1); |
my $key = ReadKey(-1); |
| 194 |
if ($key) { |
if ($key) { |
| 195 |
|
|
|
$heap->{state}{KeyPressed} = 1; |
|
|
|
|
| 196 |
# normal key? |
# normal key? |
| 197 |
if ($key =~ m/[a-zA-Z? ]/) { |
if ($key =~ m/[a-zA-Z? ]/) { |
| 198 |
$heap->{state}{InputBuffer} .= $key; |
$heap->{state}{InputBuffer} .= $key; |
| 200 |
} |
} |
| 201 |
|
|
| 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"; |
| 223 |
$heap->{state}{InputBuffer} = substr($heap->{state}{InputBuffer}, 0, -1); |
$heap->{state}{InputBuffer} = substr($heap->{state}{InputBuffer}, 0, -1); |
| 224 |
} |
} |
| 225 |
|
|
| 226 |
|
# mark "KeyPressed" for next poll |
| 227 |
|
$heap->{state}{KeyPressed} = 1; |
| 228 |
|
|
| 229 |
} |
} |
| 230 |
|
|
| 231 |
|
#$kernel->post($session, "pollForKey"); |
| 232 |
$kernel->post($session, "pollForKey"); |
#$kernel->delay("pollForKey", 0.1); |
| 233 |
#$kernel->delay("term_work", 0.1); |
$kernel->delay("pollForKey", 0.01); |
| 234 |
|
|
| 235 |
} |
} |
| 236 |
|
|