fix longstanding issues with console EOL handling
authorDirk Koopman <djk@tobit.co.uk>
Sat, 4 Jul 2020 01:03:29 +0000 (02:03 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Sat, 4 Jul 2020 01:09:08 +0000 (02:09 +0100)
Historically there has been an issue with line endings in console.pl
which meant that the spot line (for instance) had to be 1 character
less than the window width (e.g. 79 chars in an 80 char window).

This has now FINALLY been fixed.

In the process I have fixed the issues of extra things like
cq/itu/us state/dxgrid strings overwriting or coming out in a
stupid priority. So the priority is now from nearest/smallest
area -> largest wiz: QRA, US State, ITU or CQ zone. So you
can have them all on, but ITU zone will always trump CQ zone.

perl/DXCommandmode.pm
perl/console.pl

index 729675be0685da73848d16f6c648c291daa7e111..e6b612fad342942b8733a6e9fce402aaa2e86ac7 100644 (file)
@@ -996,18 +996,11 @@ sub format_dx_spot
 
        my $t = ztime($_[2]);
        my $loc = '';
-       my $clth = $self->{consort} eq 'local' ? 29 : 30;
+       my $clth = 30;
+       --$clth if $self->{consort} eq 'local';
+       
        my $comment = substr (($_[3] || ''), 0, $clth);
        $comment .= ' ' x ($clth - (length($comment)));
-       if ($self->{user}->wantgrid) {
-               my $ref = DXUser::get_current($_[1]);
-               if ($ref && $ref->qra) {
-                       $loc = ' ' . substr($ref->qra, 0, 4);
-                       $comment = substr $comment, 0,  ($clth - (length($comment)+length($loc)));
-                       $comment .= $loc;
-                       $loc = '';
-               }
-       }
        
        if ($self->{user}->wantgrid) {
                my $ref = DXUser::get_current($_[4]);
@@ -1016,15 +1009,23 @@ sub format_dx_spot
                }
        }
 
-       if ($self->{user}->wantdxitu) {
+    if ($self->{user}->wantgrid) {
+               my $ref = DXUser::get_current($_[1]);
+               if ($ref && $ref->qra) {
+                       $loc = ' ' . substr($ref->qra, 0, 4);
+                       $comment = substr $comment, 0,  ($clth - (length($comment)+length($loc)));
+                       $comment .= $loc;
+                       $loc = '';
+               }
+       } elsif ($self->{user}->wantdxitu) {
                $loc = ' ' . sprintf("%2d", $_[10]) if defined $_[10];
-               $comment = substr($comment, 0,  $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[8]) if defined $_[8]; 
+               $comment = substr($comment, 0,  $clth-3) . ' ' . sprintf("%2d", $_[8]) if defined $_[8]; 
        } elsif ($self->{user}->wantdxcq) {
                $loc = ' ' . sprintf("%2d", $_[11]) if defined $_[11];
-               $comment = substr($comment, 0,  $self->{consort} eq 'local' ? 26 : 27) . ' ' . sprintf("%2d", $_[9]) if defined $_[9]; 
+               $comment = substr($comment, 0, $clth-3) . ' ' . sprintf("%2d", $_[9]) if defined $_[9]; 
        } elsif ($self->{user}->wantusstate) {
                $loc = ' ' . $_[13] if $_[13];
-               $comment = substr($comment, 0,  $self->{consort} eq 'local' ? 26 : 27) . ' ' . $_[12] if $_[12]; 
+               $comment = substr($comment, 0,  $clth-3) . ' ' . $_[12] if $_[12]; 
        }
 
        return sprintf "DX de %-7.7s%11.1f  %-12.12s %-s $t$loc", "$_[4]:", $_[0], $_[1], $comment;
index cd4a44927e5799c8bf13a2858bb5c11a97972f56..97b6220df84dbdec0663dc3263c368bc19faee32 100755 (executable)
@@ -180,13 +180,18 @@ sub measure
 sub show_screen
 {
        if ($spos == @shistory - 1) {
-
                # if we really are scrolling thru at the end of the history
                my $line = $shistory[$spos];
-               $top->addstr("\n") if $spos > 0;
+               my $y = $spos;
+               if ($spos >= $pagel) {
+                       $top->scrl(1);
+                       $y = $pagel-1;
+#                      $top->addstr("\r");
+               }
+               $top->move($y, 0);
+               $top->refresh;
                setattr($line);
                $top->addstr($line);
-#              $top->addstr("\n");
                $top->attrset(COLOR_PAIR(0)) if $has_colors;
                $spos = @shistory;
                
@@ -208,8 +213,7 @@ sub show_screen
                for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
                        my $line = $shistory[$p];
                        my $lines = measure($line);
-                       last if $i + $lines > $pagel;
-                       $top->addstr("\n") if $i;
+                       $top->move($i, 0);
                        setattr($line);
                        $top->addstr($line);
                        $top->attrset(COLOR_PAIR(0)) if $has_colors;
@@ -242,7 +246,8 @@ sub addtotop
                if ($inbuf =~ s/\x07+$//) {
                        beep();
                }
-               if (length $inbuf >= $cols) {
+               $inbuf =~ s/\s+$//s;
+               if (length $inbuf > $cols) {
                        $Text::Wrap::Columns = $cols;
                        push @shistory, wrap('',"\t", $inbuf);
                } else {