From: Dobrica Pavlinusic Date: Sun, 2 Jan 2005 22:09:01 +0000 (+0000) Subject: yet another progress bar fix X-Git-Url: http://git.rot13.org/?p=webpac;a=commitdiff_plain;h=6f44d21b03902e821250f585654b7a6d07780a8c yet another progress bar fix git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@628 13eb9ef6-21d5-0310-b721-a9d68796d827 --- diff --git a/all2xml.pl b/all2xml.pl index 02b2d2c..3fc1299 100755 --- a/all2xml.pl +++ b/all2xml.pl @@ -687,8 +687,9 @@ print STDERR "reading ./import_xml/$type.xml\n"; my $current = shift; my $total = shift || 1; my $p = int($current * 100 / $total); - if ($p < $last_p) { + if ($p < $last_p || $current == 1) { $start_t = time(); + $last_p = 0; } elsif ($p != $last_p) { my $rate = ($current / (time() - $start_t || 1)); my $eta = ($total-$current) / ($rate || 1); @@ -698,16 +699,30 @@ print STDERR "reading ./import_xml/$type.xml\n"; } my $fake_dir = 1; + my $fake_pos = 0; + my $last_fake_t = time(); sub fakeprogress { return if (! $show_progress); my $current = shift @_; - my @ind = ('-','\\','|','/','-','\\','|','/', '-'); + my @ind = ('-','\\','|','/','-','\\','|','/'); - $last_p += $fake_dir; - $fake_dir = -$fake_dir if ($last_p > 1000 || $last_p < 0); - if ($last_p % 10 == 0) { - printf STDERR ("%5d / %5s [%-51s]\r",$current,"?"," " x ($last_p/20).$ind[($last_p/20) % $#ind]); + if ($current < $fake_pos) { + $start_t = time(); + $last_fake_t = 0; + $fake_dir = 1; + $fake_pos = 0; + } + + if (time()-$last_fake_t >= 1) { + $last_fake_t = time(); + $fake_pos += $fake_dir; + $fake_dir = -$fake_dir if ($fake_pos > 38); + } + + if ($current % 10 == 0) { + my $rate = ($current / (time() - $start_t || 1)); + printf STDERR ("%5d [%-38s] %0.1f/s\r",$current, " " x $fake_pos .$ind[($current / 10) % 8], $rate); } }