/[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.5 by cvsjoko, Sat Jun 15 05:19:36 2002 UTC revision 1.6 by cvsjoko, Sat Jun 15 07:46:11 2002 UTC
# Line 5  Line 5 
5  ## $Id$  ## $Id$
6  ##  ##
7  ## $Log$  ## $Log$
8    ## Revision 1.6  2002/06/15 07:46:11  cvsjoko
9    ## + bugfixes for linux
10    ##
11  ## Revision 1.5  2002/06/15 05:19:36  cvsjoko  ## Revision 1.5  2002/06/15 05:19:36  cvsjoko
12  ## + modified order/way of key-handling-logic  ## + modified order/way of key-handling-logic
13  ##  ##
# Line 109  sub start { Line 112  sub start {
112    $heap->{state}{InputBuffer} = '';    $heap->{state}{InputBuffer} = '';
113    $heap->{state}{Startup} = 1;    $heap->{state}{Startup} = 1;
114    $heap->{state}{Caption} = $self->{Caption};    $heap->{state}{Caption} = $self->{Caption};
115      $heap->{state}{KeyPressed} = 0;
116      $heap->{state}{RequestPending} = 0;
117        
118    # initially call worker-state    # initially call worker-state
119      ReadMode 4;
120    $kernel->post($session, "pollForKey");    $kernel->post($session, "pollForKey");
121    
122    return;    return;
# Line 184  sub pollForKey { Line 190  sub pollForKey {
190    my $prompt = "#> ";    my $prompt = "#> ";
191    $prompt = $self->{PromptPrefix} . ' ' . $prompt_inlay . $self->{PromptPostfix};    $prompt = $self->{PromptPrefix} . ' ' . $prompt_inlay . $self->{PromptPostfix};
192    
193    if ( ($heap->{state}{KeyPressed} && !$heap->{state}{RequestPending}) || ($heap->{state}{Startup}) ) {    if ( (
194            ( $heap->{state}{KeyPressed} == 1 ) &&
195            ( $heap->{state}{RequestPending} == 0 )
196           ) ||
197            ( $heap->{state}{Startup} )
198          ) {
199      $heap->{state}{Startup} = 0;      $heap->{state}{Startup} = 0;
200      $heap->{state}{KeyPressed} = 0;      $heap->{state}{KeyPressed} = 0;
     #ReadMode 4; # Turn off controls keys  
     #ReadMode 1;  
     #print $prompt;  
201      my $outputline = $prompt . $heap->{state}{InputBuffer};      my $outputline = $prompt . $heap->{state}{InputBuffer};
202      my $s = ' ' x (length($outputline) + 1);      my $s = ' ' x (length($outputline) + 1);
203      print "\r", $s;      print "\r", $s;
204      print "\r", $outputline;      print "\r", $outputline;
205        #print $outputline;
206    }    }
207    
208    my $key = ReadKey(-1);    my $key = ReadKey(-1);
209    if ( defined $key ) {    if ( defined $key ) {
210    
211    #print "key: ", ord($key), "\n";
212            
213        # CTRL+C pressed?
214        if (ord($key) == 3) {
215          ReadMode 1;
216          print "\n";
217          exit;
218        }
219    
220      # enter pressed?      # enter pressed?
221      if ($key eq $self->{conf}{EnterKey}) {      if (ord($key) == 10) {
222        # send command  
223          # if enter was pressed while request was pending,
224          # we should stop waiting for output and come back to prompt again,
225          if ($heap->{state}{RequestPending}) {
226            $kernel->post( $self->{ResponseSession} => $self->{ResponseState} => '  < stopped waiting for response');
227          }
228    
229          # send command, if buffer is filled
230        my $buf = $heap->{state}{InputBuffer};        my $buf = $heap->{state}{InputBuffer};
231        if ($buf) {        if ($buf) {
232          $heap->{state}{InputBuffer} = '';          $heap->{state}{InputBuffer} = '';
233          $heap->{state}{RequestPending} = 1;          $heap->{state}{RequestPending} = 1;
         #print "ord: ", ord($buf), "\n";  
234          my $response_target = {          my $response_target = {
235            ResponseSession => $self->{ResponseSession},            ResponseSession => $self->{ResponseSession},
236            ResponseState => $self->{ResponseState},            ResponseState => $self->{ResponseState},
# Line 216  sub pollForKey { Line 240  sub pollForKey {
240    
241        # prepare new loop for fresh prompt        # prepare new loop for fresh prompt
242        print "\n";        print "\n";
243    
244      }      }
245    
246      # backspace pressed?      # backspace pressed?
247      elsif (ord($key) == 8) {      elsif (ord($key) == 127) {
248        $heap->{state}{InputBuffer} = substr($heap->{state}{InputBuffer}, 0, -1);        $heap->{state}{InputBuffer} = substr($heap->{state}{InputBuffer}, 0, -1);
249      }      }
250    
# Line 235  sub pollForKey { Line 260  sub pollForKey {
260    
261    }    }
262    
263      #$kernel->run_one_timeslice();
264    $kernel->post($session, "pollForKey");    $kernel->post($session, "pollForKey");
265      #$kernel->yield($session, "pollForKey");
266    #$kernel->delay("pollForKey", 0.1);    #$kernel->delay("pollForKey", 0.1);
267    #$kernel->delay("pollForKey", 0.01);    #$kernel->delay("pollForKey", 0.01);
268    
# Line 246  sub pollForKey { Line 273  sub pollForKey {
273    
274  sub recieveResponse {  sub recieveResponse {
275    my ($kernel, $heap, $session, $response) = @_[KERNEL, HEAP, SESSION, ARG0];    my ($kernel, $heap, $session, $response) = @_[KERNEL, HEAP, SESSION, ARG0];
276    if ($response) { print $response, "\n"; }    if ($response) {
277    $heap->{state}{RequestPending} = 0;      print $response, "\n";
278        $heap->{state}{RequestPending} = 0;
279      }
280  }  }
281  sub recievePrompt {  sub recievePrompt {
282    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.5  
changed lines
  Added in v.1.6

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