From fb40336949e32d436b3bf23d9098722b6ed79c8c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 29 Apr 2009 16:30:12 +0200 Subject: Improved progressbar --- include/gen-xhtml-thumbnails | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/include/gen-xhtml-thumbnails b/include/gen-xhtml-thumbnails index 3c64ea9..1ab433c 100755 --- a/include/gen-xhtml-thumbnails +++ b/include/gen-xhtml-thumbnails @@ -7,9 +7,24 @@ my $directory = shift || '.'; my $thumbdir = "$directory/.thumbs"; my $indexfile = "$directory/index.xhtml"; my ($file, $image, $thumb); -my ($dx, $dy, $tx, $ty); +my ($dx, $dy); +my @files; +my $number = 0; + +sub print_progress { + if (($number % 60) == 0) { + if ($number) { + printf(" %4d/%d\n", $number, scalar(@files)); + } + printf('[%3d%%] ', $number * 100 / @files); + } elsif (($number % 10) == 0) { + print ' '; + } +} + $| = 1; open(my $index, '>', $indexfile); + print $index < @@ -27,14 +42,20 @@ if (! -d $thumbdir) { } opendir(my $dirhandle, $directory) or die("Cannot open $directory: $!"); -print "Generating thumbnails [ - cached | + generated ]\n"; foreach $file (readdir($dirhandle)) { - next unless ($file =~ /\.(png|jpe?g)$/i); + push(@files, $file) if ($file =~ /\.(png|jpe?g)$/i); +} +closedir($dirhandle); + +print "Generating thumbnails [ - cached | + generated ]\n"; +foreach $file (@files) { print $index < ficken + print_progress; + $number++; if (-e "$thumbdir/$file") { print '-'; next; -- cgit v1.2.3