Fix spurious Text::Wrap warning on console.pl
[spider.git] / perl / console.pl
index d01cd5390e8a88af39b8324dfe67c76ecd66a999..faf7c5ce062890e26090264a64b4d617203e038f 100755 (executable)
@@ -13,7 +13,7 @@
 #
 # 
 
-require 5.004;
+require 5.16.1;
 use warnings;
 
 # search local then perl directories
@@ -132,8 +132,26 @@ sub doresize
        do_initscr();
 
        $inscroll = 0;
+       dbg("resize: l=$lines c=$cols");
+       dbg("resize: sh=". scalar @sh );
+#      my @tsh;
+#      my $t;
+#      while (defined ($t = shift @sh)) {
+#              dbg("t: $t(" , length $t . ')'); 
+#              if ($t =~ /^\t/) {
+#                      $t =~ s/^\t/ /;
+#                      push(@tsh, pop(@tsh) . $t)
+#              } else {
+#                      push(@tsh, $t);
+#              }
+#              dbg("tsh: " . scalar @tsh);
+#      }
+#      dbg("resize: tsh=". scalar @tsh );
+#      $spos = @tsh < $pagel ? 0 :  @tsh - $pagel;
+       #       addtotop(@tsh);
        $spos = @sh < $pagel ? 0 :  @sh - $pagel;
        show_screen();
+       $conn->send_later("C$call|$cols") if $conn;
 }
 
 # cease communications
@@ -454,10 +472,15 @@ sub addtotop
        while (@_) {
                my $inbuf = shift;
                my $l = length $inbuf;
+               dbg("addtotop: $l $inbuf");
                if ($l > $cols) {
-#                      $Text::Wrap::Columns = $cols;
-#                      push @sh, wrap('',"\t", $inbuf);
-                       push @sh, $inbuf;
+                       $inbuf =~ s/\s+/ /g;
+                       if (length $inbuf > $cols) {
+                               $Text::Wrap::columns = $cols;
+                               push @sh, split /\n/, wrap('',' ' x 19, $inbuf);
+                       } else {
+                               push @sh, $inbuf;
+                       }
                } else {
                        push @sh, $inbuf;
                }
@@ -551,7 +574,7 @@ sub on_disconnect
 while (@ARGV && $ARGV[0] =~ /^-/) {
        my $arg = shift;
        if ($arg eq '-x') {
-               dbginit();
+               dbginit('console');
                dbgadd('console');
                $maxshist = 200;
        }
@@ -580,13 +603,13 @@ unless ($DB::VERSION) {
 
 $SIG{'HUP'} = \&sig_term;
 
-# start up
+
+# start upb
+$Text::Wrap::columns = $cols;
 doresize();
 
 $SIG{__DIE__} = \&sig_term;
 
-#$Text::Wrap::Columns = $cols;
-
 my $lastmin = 0;