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

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