made the console.pl work with history and editing
authordjk <djk>
Mon, 28 Jun 1999 15:42:57 +0000 (15:42 +0000)
committerdjk <djk>
Mon, 28 Jun 1999 15:42:57 +0000 (15:42 +0000)
Changes
perl/console.pl

diff --git a/Changes b/Changes
index 6dcfa6ed56d7d9db42c8ea0e42e2d58883f507e9..e9b7a3886245918adf85590a318eef6fdd7d9d2c 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,5 @@
+28Jun99=======================================================================
+1. console.pl now works with history and editting.
 27Jun99=======================================================================
 1. added WWV filtering
 2. added timeouts to for forwarding Messages, also added a waiting time for
index 12192152e827b6a0c663d684a577313555aeb90a..02a2e476831ef0567d21dc7c384c8d27a52c84bb 100755 (executable)
@@ -64,11 +64,12 @@ sub rec_socket
                my ($sort, $call, $line) = $msg =~ /^(\w)(\S+)\|(.*)$/;
                
                if ($sort eq 'D') {
-                       $top->addstr("$line\n");
+                       $top->addstr("\n$line");
                } elsif ($sort eq 'Z') { # end, disconnect, go, away .....
                        cease(0);
                }         
        }
+       $top->refresh();
        $lasttime = time; 
 }
 
@@ -84,14 +85,99 @@ sub rec_stdin
        #  $prbuf =~ s/\n/\\n/;
        #  print "sys: $r ($prbuf)\n";
        if (defined $r) {
-               if ($r eq "\n" || $r eq "\r") {
+               if ($r eq KEY_ENTER || $r eq "\n" || $r eq "\r") {
+                       
+                       # save the lines
+                       if ($inbuf) {
+                               push @history, $inbuf if $inbuf;
+                               shift @history if @history > $maxhist;
+                               $histpos = @history;
+                               $bot->move(0,0);
+                               $bot->addstr(substr($inbuf, 0, COLS));
+                       }
+               
+                       # send it to the cluster
                        $inbuf = " " unless $inbuf;
-                       $conn->send_later("I|$call|$inbuf");
+                       $conn->send_later("I$call|$inbuf");
+                       $inbuf = "";
+                       $pos = $lth = 0;
+               } elsif ($r eq KEY_UP || $r eq KEY_PPAGE || $r eq "\020") {
+                       if ($histpos > 0) {
+                               --$histpos;
+                               $inbuf = $history[$histpos];
+                               $pos = $lth = length $inbuf;
+                       } else {
+                               beep();
+                       }
+               } elsif ($r eq KEY_DOWN || $r eq KEY_NPAGE || $r eq "\016") {
+                       if ($histpos < @history - 1) {
+                               ++$histpos;
+                               $inbuf = $history[$histpos];
+                               $pos = $lth = length $inbuf;
+                       } else {
+                               beep();
+                       }
+               } elsif ($r eq KEY_LEFT || $r eq "\002") {
+                       if ($pos > 0) {
+                               --$pos;
+                       } else {
+                               beep();
+                       }
+               } elsif ($r eq KEY_RIGHT || $r eq "\006") {
+                       if ($pos < $lth) {
+                               ++$pos;
+                       } else {
+                               beep();
+                       }
+               } elsif ($r eq KEY_HOME) {
+                       $pos = 0;
+               } elsif ($r eq KEY_BACKSPACE || $r eq "\010") {
+                       if ($pos > 0) {
+                               my $a = substr($inbuf, 0, $pos-1);
+                               my $b = substr($inbuf, $pos) if $pos < $lth;
+                               $b = "" unless $b;
+                               
+                               $inbuf = $a . $b;
+                               --$lth;
+                               --$pos;
+                       } else {
+                               beep();
+                       }
+               } elsif ($r eq KEY_DC || $r eq "\004") {
+                       if ($pos < $lth) {
+                               my $a = substr($inbuf, 0, $pos);
+                               my $b = substr($inbuf, $pos+1) if $pos < $lth;
+                               $b = "" unless $b;
+                               
+                               $inbuf = $a . $b;
+                               --$lth;
+                       } else {
+                               beep();
+                       }
+               } elsif ($r ge ' ' && $r le '~') {
+                       if ($pos < $lth) {
+                               my $a = substr($inbuf, 0, $pos);
+                               my $b = substr($inbuf, $pos);
+                               $inbuf = $a . $r . $b;
+                       } else {
+                               $inbuf .= $r;
+                       }
+                       $pos++;
+                       $lth++;
+               } elsif ($r eq "\014" || $r eq "\022") {
+                       $scr->touchwin();
+                       $scr->refresh();
+               } elsif ($r eq "\013") {
                        $inbuf = "";
+                       $pos = $lth = 0;
                } else {
-                       $inbuf .= $r;
+                       beep();
                }
+               $bot->move(1, 0);
+               $bot->clrtobot();
+               $bot->addstr($inbuf);
        } 
+       $bot->move(1, $pos);
        $bot->refresh();
 }
 
@@ -105,6 +191,11 @@ $conn = 0;                      # the connection object for the cluster
 $lasttime = time;               # lasttime something happened on the interface
 
 $connsort = "local";
+@history = ();
+$histpos = 0;
+$maxhist = 100;
+$pos = $lth = 0;
+$inbuf = "";
 
 #
 # deal with args
@@ -138,7 +229,8 @@ $SIG{'TERM'} = \&sig_term;
 $SIG{'HUP'} = 'IGNORE';
 
 $scr = new Curses;
-cbreak();
+raw();
+noecho();
 $top = $scr->subwin(LINES()-4, COLS, 0, 0);
 $top->intrflush(0);
 $top->scrollok(1);
@@ -147,13 +239,16 @@ $bot = $scr->subwin(3, COLS, LINES()-3, 0);
 $bot->intrflush(0);
 $bot->scrollok(1);
 $bot->keypad(1);
+$bot->move(1,0);
 $scr->refresh();
 
+$SIG{__DIE__} = \&sig_term;
+
 $pages = LINES()-6;
 
 $conn->send_now("A$call|$connsort");
-$conn->send_now("I|$call|set/page $pages");
-$conn->send_now("I|$call|set/nobeep");
+$conn->send_now("I$call|set/page $pages");
+$conn->send_now("I$call|set/nobeep");
 
 Msg->set_event_handler(\*STDIN, "read" => \&rec_stdin);