reopen 475140
thanks

There is a full redrawing instead a screen cleaning in the flicker.diff
patch. And some points about modes switching were not taken into
consideration. As the result the screen was not redrawed sometimes.

This was my fault, please, excuse me :)

The attached patch that will fix this problem. Please replace the file
flicker.diff


--- mytop-1.6.orig/mytop	2008-04-27 02:06:33.000000000 +0400
+++ mytop-1.6/mytop	2008-04-27 02:08:17.000000000 +0400
@@ -73,6 +73,7 @@
 ## Default Config Values
 
 my %config = (
+    vt100         => 0,
     batchmode     => 0,
     color         => 1,
     db            => '',
@@ -104,6 +105,15 @@
 
 my $CLEAR = $WIN ? '': `clear`;
 
+my %vt100_commands=
+(
+  CURSOR_TO_START     => "\x1b[0;0f",
+  CURSOR_SAVE         => "\x1b[s",
+  CURSOR_RESTORE      => "\x1b[u",
+  EEL                 => "\x1b[K",  # Erase end of line
+  EEB                 => "\x1b[J",  # Erase down
+);
+
 ## Term::ReadKey values
 
 my $RM_RESET   = 0;
@@ -140,6 +150,7 @@
 Getopt::Long::Configure('no_ignore_case', 'bundling');
 
 GetOptions(
+    "vt100"               => \$config{vt100},
     "color!"              => \$config{color},
     "user|u=s"            => \$config{user},
     "pass|password|p=s"   => \$config{pass},
@@ -158,6 +169,9 @@
     "sort=s"              => \$config{sort},
 );
 
+($config{batchmode} or not -t STDOUT)
+  and $config{vt100}=0;
+
 ## User may have put the port with the host.
 
 if ($config{host} =~ s/:(\d+)$//)
@@ -171,6 +185,7 @@
 {
     require Term::ReadKey;
     Term::ReadKey->import();
+    Clear();
 }
 
 ## User may want to disable color.
@@ -682,6 +697,14 @@
     }
 }
 
+sub CursorToStartNotClear()
+{
+  local $\;
+  $config{vt100} or return Clear;
+  $WIN and return Clear;
+  print $vt100_commands{CURSOR_TO_START};
+}
+
 my $last_time;
 
 sub GetData()
@@ -693,6 +716,8 @@
 
     my ($width, $height, $wpx, $hpx, $lines_left);
 
+    local $\=$config{vt100}?"$vt100_commands{EEL}\n":"\n";
+
     if (not $config{batchmode})
     {
         ($width, $height, $wpx, $hpx) = GetTerminalSize();
@@ -810,16 +835,16 @@
         my $host_width = 52;
         my $up_width   = $width - $host_width;
 
-        Clear() unless $config{batchmode};
-        print RESET();
+        CursorToStartNotClear() unless $config{batchmode};
+        { local $\; print RESET(); }
 
-        printf "%-${host_width}s%${up_width}s\n",
+        printf "%-${host_width}s%${up_width}s",
                "MySQL on $config{host} ($db_version)",
                "up $uptime $current_time";
         $lines_left--;
 
 
-        printf " Queries: %-5s  qps: %4.0f Slow: %7s         Se/In/Up/De(%%):    %02.0f/%02.0f/%02.0f/%02.0f \n",
+        printf " Queries: %-5s  qps: %4.0f Slow: %7s         Se/In/Up/De(%%):    %02.0f/%02.0f/%02.0f/%02.0f ",
                make_short( $STATUS{Questions} ),  # q total
                $STATUS{Questions} / $STATUS{Uptime},  # qps, average
                make_short( $STATUS{Slow_queries} ),    # slow
@@ -835,9 +860,9 @@
         if ($t_delta)
         {
           my $q_diff = ( $STATUS{Questions} - $OLD_STATUS{Questions} );
-#          print("q_diff: $STATUS{Questions} - $OLD_STATUS{Questions}  / $t_delta = $q_diff\n");
+#          print("q_diff: $STATUS{Questions} - $OLD_STATUS{Questions}  / $t_delta = $q_diff");
 
-          printf("             qps now: %4.0f Slow qps: %3.1f  Threads: %4.0f (%4.0f/%4.0f) %02.0f/%02.0f/%02.0f/%02.0f \n",
+          printf("             qps now: %4.0f Slow qps: %3.1f  Threads: %4.0f (%4.0f/%4.0f) %02.0f/%02.0f/%02.0f/%02.0f ",
                  ( $STATUS{Questions} - $OLD_STATUS{Questions} ) / $t_delta,
                  ( # slow now (qps)
                   ($STATUS{Slow_queries} ) ?
@@ -860,13 +885,13 @@
         }
         else
         {
-            print "\n";
+            print "";
         }
         $lines_left--;
 
         if ($have_query_cache and $STATUS{Com_select} and $query_cache_hits)
         {
-          printf(" Cache Hits: %-5s Hits/s: %4.1f Hits now: %5.1f  Ratio: %4.1f%% Ratio now: %4.1f%% \n", 
+          printf(" Cache Hits: %-5s Hits/s: %4.1f Hits now: %5.1f  Ratio: %4.1f%% Ratio now: %4.1f%% ", 
                  make_short($STATUS{Qcache_hits}),        # cache hits
                  $STATUS{Qcache_hits} / $STATUS{Uptime}, # hits / sec
                  ($t_delta) ?  ($STATUS{Qcache_hits} - $OLD_STATUS{Qcache_hits}) / $t_delta : 0,  # now / s
@@ -889,15 +914,16 @@
                make_short(($STATUS{Bytes_received} - $OLD_STATUS{Bytes_received}) / $t_delta ),
                make_short(($STATUS{Bytes_sent} - $OLD_STATUS{Bytes_sent}) / $t_delta ))
           if ($t_delta);
-        print "\n\n";
+        print "";
+        print "";
 
         $lines_left--;
     }
 
     if (not $config{batchmode} and not $config{header})
     {
-        Clear();
-        print RESET();
+        CursorToStartNotClear();
+        local $\; print RESET();
     }
 
     ##
@@ -909,15 +935,15 @@
     my $used = scalar(@sz) + Sum(@sz);
     my $free = $width - $used;
 
-    print BOLD();
+    { local $\; print BOLD(); }
 
-    printf "%8s %9s %15s %10s %9s %6s %-${free}s\n",
+    printf "%8s %9s %15s %10s %9s %6s %-${free}s",
         'Id','User','Host/IP','DB','Time', 'Cmd', 'Query or State';
 
-    print RESET();
+    { local $\; print RESET(); }
 
     ##      Id User Host DB
-    printf "%8s %9s %15s %10s %9s %6s %-${free}s\n",
+    printf "%8s %9s %15s %10s %9s %6s %-${free}s",
         '--','----','-------','--','----', '---', '----------';
 
     $lines_left -= 2;
@@ -1042,23 +1067,25 @@
 
         if ($HAS_COLOR)
         {
+            local $\;
             print YELLOW() if $thread->{Command} eq 'Query';
             print WHITE()  if $thread->{Command} eq 'Sleep';
             print GREEN()  if $thread->{Command} eq 'Connect';
         }
 
-        printf "%8d %9.9s %15.15s %10.10s %9d %6.6s %-${free}.${free}s\n",
+        printf "%8d %9.9s %15.15s %10.10s %9d %6.6s %-${free}.${free}s",
             $thread->{Id}, $thread->{User}, $thread->{Host}, $thread->{db},
             $thread->{Time}, $thread->{Command}, $smInfo;
 
-        print RESET() if $HAS_COLOR;
+        { local $\; print RESET() if $HAS_COLOR; }
 
         $lines_left--;
 
         last if $lines_left == 0;
-
     }
 
+    $config{vt100} and 
+      print "$vt100_commands{EEL}$vt100_commands{EEB}";
 }
 
 ###########################################################################
@@ -1709,6 +1736,11 @@
 Use if you'd like B<mytop> to connect to a specific database by
 default. Default: none.
 
+=item B<--vt100>
+
+For  screen re-drawing use esc-sequence vt100. It is remove terminal 
+twinkling.
+
 =item B<-b> or B<--batch> or B<--batchmode>
 
 In batch mode, mytop runs only once, does not clear the screen, and

Attachment: signature.asc
Description: Digital signature

Reply via email to