Bug#475140: the patch for removing the terminal flicker

2008-04-27 Thread Dmitry E. Oboukhov
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.0 +0400
+++ mytop-1.6/mytop	2008-04-27 02:08:17.0 +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(

Bug#475140: the patch for removing the terminal flicker

2008-04-23 Thread Dmitry E. Oboukhov
DBTS> Recently I've begun to use mytop. Everything is very comfortable except
DBTS> the fact that the terminal flickers when repainting. I've written the
DBTS> patch removing this effect.

DBTS> Unfortunately I can't test it on many platforms so I've realised it as
DBTS> an additional option --vt100.

last version for this patch (attache)

no artefacts )

--- old/mytop-1.6/mytop	2008-04-23 11:37:57.0 +0400
+++ new/mytop-1.6/mytop	2008-04-23 11:37:34.0 +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,13 @@
 }
 }
 
+sub CursorToStartNotClear()
+{
+  $config{vt100} or return Clear;
+  $WIN and return Clear;
+  print $vt100_commands{CURSOR_TO_START};
+}
+
 my $last_time;
 
 sub GetData()
@@ -693,6 +715,8 @@
 
 my ($width, $height, $wpx, $hpx, $lines_left);
 
+local $\=$config{vt100}?"$vt100_commands{EEL}":'';
+
 if (not $config{batchmode})
 {
 ($width, $height, $wpx, $hpx) = GetTerminalSize();
@@ -810,7 +834,7 @@
 my $host_width = 52;
 my $up_width   = $width - $host_width;
 
-Clear() unless $config{batchmode};
+CursorToStartNotClear() unless $config{batchmode};
 print RESET();
 
 printf "%-${host_width}s%${up_width}s\n",
@@ -896,7 +920,7 @@
 
 if (not $config{batchmode} and not $config{header})
 {
-Clear();
+CursorToStartNotClear();
 print RESET();
 }
 
@@ -1059,6 +1082,8 @@
 
 }
 
+$config{vt100} and 
+  print "$vt100_commands{EEL}$vt100_commands{EEB}";
 }
 
 ###
@@ -1709,6 +1734,11 @@
 Use if you'd like B 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


signature.asc
Description: Digital signature


Bug#475140: the patch for removing the terminal flicker

2008-04-09 Thread Dmitry E. Oboukhov
Package: mytop
Version: 1.6
Severity: normal
Tags: patch

see attache

Recently I've begun to use mytop. Everything is very comfortable except
the fact that the terminal flickers when repainting. I've written the
patch removing this effect.

Unfortunately I can't test it on many platforms so I've realised it as
an additional option --vt100.
--- mytop	2008-04-09 12:14:52.0 +0400
+++ mytop	2008-04-09 14:10:25.0 +0400
@@ -76,6 +76,7 @@
 ## Default Config Values
 
 my %config = (
+vt100 => 0,
 batchmode => 0,
 color => 1,
 db=> 'test',
@@ -107,6 +108,13 @@
 
 my $CLEAR = $WIN ? '': `clear`;
 
+my %vt100_commands=
+(
+  CURSOR_TO_START => "\x1b[0;0f",
+  CURSOR_SAVE => "\x1b[s",
+  CURSOR_RESTORE  => "\x1b[u",
+);
+
 ## Term::ReadKey values
 
 my $RM_RESET   = 0;
@@ -143,6 +151,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},
@@ -161,6 +170,8 @@
 "sort=s"  => \$config{sort},
 );
 
+-t STDOUT or $config{vt100}=undef;
+
 ## User may have put the port with the host.
 
 if ($config{host} =~ s/:(\d+)$//)
@@ -685,6 +696,13 @@
 }
 }
 
+sub CursorToStartNotClear()
+{
+  $config{vt100} or return Clear;
+  $WIN and return Clear;
+  print $vt100_commands{CURSOR_TO_START};
+}
+
 my $last_time;
 
 sub GetData()
@@ -813,7 +831,7 @@
 my $host_width = 52;
 my $up_width   = $width - $host_width;
 
-Clear() unless $config{batchmode};
+CursorToStartNotClear() unless $config{batchmode};
 print RESET();
 
 printf "%-${host_width}s%${up_width}s\n",
@@ -899,7 +917,7 @@
 
 if (not $config{batchmode} and not $config{header})
 {
-Clear();
+CursorToStartNotClear();
 print RESET();
 }
 
@@ -1059,6 +1077,13 @@
 
 }
 
+
+if ($config{vt100} and not $config{batchmode})
+{
+  print $vt100_commands{CURSOR_SAVE};
+  print join "\n", (" "x$width)x($lines_left+2);
+  print $vt100_commands{CURSOR_RESTORE};
+}
 }
 
 ###
@@ -1706,6 +1731,11 @@
 Use if you'd like B to connect to a specific database by
 default. Default: ``B''.
 
+=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


signature.asc
Description: Digital signature