a more robust console.pl idle loop fix
[spider.git] / perl / console.pl
index 48c7ff8c1c756210911f4250a79980f6ca0c3c2b..d01cd5390e8a88af39b8324dfe67c76ecd66a999 100755 (executable)
@@ -52,6 +52,7 @@ use Console;
 #
 
 $call = "";                     # the callsign being used
+$node = "";                     # the node callsign being used
 $conn = 0;                      # the connection object for the cluster
 $lasttime = time;               # lasttime something happened on the interface
 
@@ -69,19 +70,13 @@ $inscroll = 0;
 
 $DXDebug::no_stdout = 1;
 
-sub mydbg
-{
-       local *STDOUT = undef;
-       dbg(@_);
-}
-
 # do the screen initialisation
 sub do_initscr
 {
        $scr = new Curses;
        if ($has_colors) {
                start_color();
-               init_pair("0", $foreground, $background);
+               init_pair(0, $foreground, $background);
 #              init_pair(0, $background, $foreground);
                init_pair(1, COLOR_RED, $background);
                init_pair(2, COLOR_YELLOW, $background);
@@ -245,12 +240,13 @@ sub show_screen
        my $size = $lines . 'x' . $cols . '-'; 
        my $add = "-$spos-$shl";
     my $time = ztime(time);
-       my $str =  "-" . $time . '-' . ($inscroll ? 'S':'-') . '-' x ($cols - (length($size) + length($call) + length($add) + length($time) + 3));
+       my $c = "$call\@$node";
+       my $str =  "-" . $time . '-' . ($inscroll ? 'S':'-') . '-' x ($cols - (length($size) + length($c) + length($add) + length($time) + 3));
        $scr->addstr($lines-4, 0, $str);
        
        $scr->addstr($size);
        $scr->attrset($mycallcolor) if $has_colors;
-       $scr->addstr($call);
+       $scr->addstr($c);
        $scr->attrset(COLOR_PAIR(0)) if $has_colors;
     $scr->addstr($add);
        $scr->refresh();
@@ -522,10 +518,10 @@ sub idle_loop
        }
        my $ch = $bot->getch();         # this is here just to catch RESIZE events
        if (defined $ch) {
-               if ($ch == KEY_RESIZE) {
+               if ($ch eq KEY_RESIZE) {
                        doresize();
                } else {
-                       rec_stdin($ch) unless $ch == '-1';
+                       rec_stdin($ch) unless $ch eq '-1';
                }
        }
        $top->refresh() if $top->is_wintouched;
@@ -554,11 +550,17 @@ sub on_disconnect
 
 while (@ARGV && $ARGV[0] =~ /^-/) {
        my $arg = shift;
-       dbgadd('console'), $maxshist = 200 if $arg eq '-x';
+       if ($arg eq '-x') {
+               dbginit();
+               dbgadd('console');
+               $maxshist = 200;
+       }
 }
 
 $call = uc shift @ARGV if @ARGV;
-$call = uc $myalias if !$call;
+$call = uc $myalias unless $call;
+$node = uc $mycall unless $node;
+
 my ($scall, $ssid) = split /-/, $call;
 $ssid = undef unless $ssid && $ssid =~ /^\d+$/;  
 if ($ssid) {
@@ -571,8 +573,6 @@ if ($call eq $mycall) {
        exit(0);
 }
 
-dbginit();
-
 unless ($DB::VERSION) {
        $SIG{'INT'} = \&sig_term;
        $SIG{'TERM'} = \&sig_term;
@@ -594,7 +594,7 @@ $conn = IntMsg->connect($clusteraddr, $clusterport, rproc => \&rec_socket);
 $conn->{on_connect} = \&on_connect;
 $conn->{on_disconnect} = \&on_disconnect;
 
-my $timer = Mojo::IOLoop->recurring(1, sub {DXLog::flushall()});
+my $timer = Mojo::IOLoop->recurring(1, sub {DXLog::flushall()}) if $DXDebug::fp;
 
 $idle = Mojo::IOLoop->recurring(0.100 => \&idle_loop);
 Mojo::IOLoop->singleton->reactor->io(\*STDIN => sub {