/[cvs]/joko/Scripts/psh/lib/POE/Component/Terminal.pm
ViewVC logotype

Diff of /joko/Scripts/psh/lib/POE/Component/Terminal.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.8

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed