| 1 | # $Id: Progress.pm 2187 2006-08-16 19:34:38Z joern $ | ||
| 2 | |||
| 3 | #----------------------------------------------------------------------- | ||
| 4 | # Copyright (C) 2001-2006 Jörn Reder <joern AT zyn.de>. | ||
| 5 | # All Rights Reserved. See file COPYRIGHT for details. | ||
| 6 | # | ||
| 7 | # This module is part of Video::DVDRip, which is free software; you can | ||
| 8 | # redistribute it and/or modify it under the same terms as Perl itself. | ||
| 9 | #----------------------------------------------------------------------- | ||
| 10 | |||
| 11 | package Video::DVDRip::Term::Progress; | ||
| 12 | |||
| 13 | use base qw( Video::DVDRip::Base ); | ||
| 14 | |||
| 15 | use Locale::TextDomain qw (video.dvdrip); | ||
| 16 | |||
| 17 | use Carp; | ||
| 18 | use strict; | ||
| 19 | |||
| 20 | my @rot = ( "|", "/", "-", "\\" ); | ||
| 21 | |||
| 22 | sub rot_idx { shift->{rot_idx} } | ||
| 23 | sub quiet { shift->{quiet} } | ||
| 24 | |||
| 25 | sub set_quiet { shift->{quiet} = $_[1] } | ||
| 26 | sub set_rot_idx { shift->{rot_idx} = $_[1] } | ||
| 27 | |||
| 28 | sub new { | ||
| 29 | my $class = shift; | ||
| 30 | my %par = @_; | ||
| 31 | my ($quiet) = @par{'quiet'}; | ||
| 32 | |||
| 33 | return bless { quiet => $quiet }, $class; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub update { | ||
| 37 | my $self = shift; | ||
| 38 | my %par = @_; | ||
| 39 | my ( $value, $label ) = @par{ 'value', 'label' }; | ||
| 40 | |||
| 41 | return if $self->quiet; | ||
| 42 | |||
| 43 | my ( $info, $percent ) = split( ":", $label, 2 ); | ||
| 44 | |||
| 45 | my $width = 76; | ||
| 46 | my $cnt = int( $width * $value ); | ||
| 47 | $cnt = $width if $cnt > $width; | ||
| 48 | |||
| 49 | my $rot_idx = $self->rot_idx; | ||
| 50 | my $rot = $rot[$rot_idx]; | ||
| 51 | ++$rot_idx; | ||
| 52 | $rot_idx = 0 if $rot_idx == @rot; | ||
| 53 | $self->set_rot_idx($rot_idx); | ||
| 54 | |||
| 55 | my $clean = chr(27) . "[K"; | ||
| 56 | my $up = chr(27) . "[1A"; | ||
| 57 | my $yel = chr(27) . "[33m"; | ||
| 58 | my $bgw = chr(27) . "[47m"; | ||
| 59 | my $reset = chr(27) . "[0m"; | ||
| 60 | my $bld = chr(27) . "[1m"; | ||
| 61 | my $rev = chr(27) . "[30;47;1m"; | ||
| 62 | my $prg = chr(27) . "[30;42m"; | ||
| 63 | |||
| 64 | my $progress = "[$prg" | ||
| 65 | . ( "·" x $cnt ) | ||
| 66 | . $reset | ||
| 67 | . ( "·" x ( $width - $cnt ) ) . "]"; | ||
| 68 | |||
| 69 | $rot = "$rev$rot$reset"; | ||
| 70 | $rot = ">" if $cnt == $width; | ||
| 71 | |||
| 72 | #-- some intelligence for l10n to align the words | ||
| 73 | #-- "Job" and "Progress" properly | ||
| 74 | my $word_job = __("Job") . ":"; | ||
| 75 | my $word_prg = __("Progress") . ":"; | ||
| 76 | |||
| 77 | my $len_job = length($word_job); | ||
| 78 | my $len_prg = length($word_prg); | ||
| 79 | |||
| 80 | my $max = $len_job > $len_prg ? $len_job : $len_prg; | ||
| 81 | |||
| 82 | $word_job = sprintf( "%-${max}s", $word_job ); | ||
| 83 | $word_prg = sprintf( "%-${max}s", $word_prg ); | ||
| 84 | |||
| 85 | print "\r$rot $progress$clean\n"; | ||
| 86 | print "\r ${yel}$word_job${reset} $bld$info$reset$clean\n"; | ||
| 87 | print "\r ${yel}$word_prg${reset} $bld$percent$reset$clean\n\r$up$up$up"; | ||
| 88 | |||
| 89 | 1; | ||
| 90 | } | ||
| 91 | |||
| 92 | sub is_active { | ||
| 93 | 0; | ||
| 94 | } | ||
| 95 | |||
| 96 | sub open { | ||
| 97 | 1; | ||
| 98 | } | ||
| 99 | |||
| 100 | sub close { | ||
| 101 | my $self = shift; | ||
| 102 | return if $self->quiet; | ||
| 103 | print "\n\n\n\n"; | ||
| 104 | 1; | ||
| 105 | } | ||
| 106 | |||
| 107 | 1; |