From: Gabor Szabo Date: Sun, 21 Jul 2013 10:33:57 +0000 (-0700) Subject: Merge pull request #3 from dsteinbrunner/patch-1 X-Git-Url: https://git.donarmstrong.com/?p=term-progressbar.git;a=commitdiff_plain;h=7bf705dc021f3d89cb56754c5a270004e3d2d08b;hp=-c Merge pull request #3 from dsteinbrunner/patch-1 typo fix --- 7bf705dc021f3d89cb56754c5a270004e3d2d08b diff --combined lib/Term/ProgressBar.pm index fb52eef,dcbc252..3ef4e55 --- a/lib/Term/ProgressBar.pm +++ b/lib/Term/ProgressBar.pm @@@ -32,7 -32,7 +32,7 @@@ A typical use sets up the progress bar calls L to update the bar whenever an item is processed. Often, this would involve updating the progress bar many times with no - user-visible change. To avoid uneccessary work, the update method returns a + user-visible change. To avoid unnecessary work, the update method returns a value, being the update value at which the user will next see a change. By only calling update when the current value exceeds the next update value, the call overhead is reduced. @@@ -240,7 -240,6 +240,7 @@@ use constant DEFAULTS => term_width => undef, term => undef, remove => 0, + silent => 0, }; use constant ETA_TYPES => { map { $_ => 1 } qw( linear ) }; @@@ -253,7 -252,7 +253,7 @@@ use constant DEBUG => 0 use vars qw($PACKAGE $VERSION); $PACKAGE = 'Term-ProgressBar'; -$VERSION = '2.13'; +$VERSION = '2.14'; # ---------------------------------- # CLASS CONSTRUCTION @@@ -285,8 -284,7 +285,8 @@@ sub __force_term # ---------------------------------- sub term_size { - my ($fh) = @_; + my ( $self, $fh ) = @_; + return if $self->silent; eval { require Term::ReadKey; @@@ -360,25 -358,6 +360,25 @@@ The filehandle to output to. Defaults *foo{THING} syntax if you want Term capabilities; it does not work. Pass in a globref instead. +=item term_width + +Sometimes we can't correctly determine the terminal width. You can use this +parameter to force a term width of a particular size. Use a positive integer, +please :) + +=item silent + +If passed a true value, Term::ProgressBar will do nothing at all. Useful in +scripts where the progress bar is optional (or just plain doesn't work due to +issues with modules it relies on). + +Instead, tell the constructor you want it to be silent and you don't need to +change the rest of your program: + + my $progress = Term::ProgressBar->new( { count => $count, silent => $silent } ); + # later + $progress->update; # does nothing + =item ETA A total time estimation to use. If enabled, a time finished estimation is @@@ -444,15 -423,13 +444,15 @@@ Class::MethodMaker->import (new_with_in sub init { my $self = shift; + return if $self->silent; # V1 Compatibility return $self->init({count => $_[1], name => $_[0], term_width => 50, bar_width => 50, major_char => '#', minor_char => '', lbrack => '', rbrack => '', - term => '0 but true', }) + term => '0 but true', + silent => 0,}) if @_ == 2; my $target; @@@ -492,7 -469,7 +492,7 @@@ die "term width $config{term_width} (from __force_term) too small" if $config{term_width} < 5; } elsif ( $config{term} and ! defined $config{term_width}) { - $config{term_width} = term_size($config{fh}); + $config{term_width} = $self->term_size($config{fh}); die if $config{term_width} < 5; } @@@ -654,7 -631,6 +654,7 @@@ Class::MethodMaker->impor offset scale fh start max_update_rate + silent /], counter => [qw/ last_position last_update /], boolean => [qw/ minor name_printed pb_ended remove /], @@@ -665,7 -641,6 +665,7 @@@ # We generate these by hand since we want to check the values. sub bar_width { my $self = shift; + return if $self->silent; return $self->{bar_width} if not @_; croak 'wrong number of arguments' if @_ != 1; croak 'bar_width < 1' if $_[0] < 1; @@@ -673,7 -648,6 +673,7 @@@ } sub term_width { my $self = shift; + return if $self->silent; return $self->{term_width} if not @_; croak 'wrong number of arguments' if @_ != 1; croak 'term_width must be at least 5' if $self->term and $_[0] < 5; @@@ -682,7 -656,6 +682,7 @@@ sub target { my $self = shift; + return if $self->silent; if ( @_ ) { my ($target) = @_; @@@ -701,7 -674,7 +701,7 @@@ sub ETA { my $self = shift; - + return if $self->silent; if (@_) { my ($type) = @_; croak "Invalid ETA type: $type\n" @@@ -769,7 -742,6 +769,7 @@@ The next value of so_far at which to ca sub update { my $self = shift; + return if $self->silent; my ($so_far) = @_; if ( ! defined $so_far ) { @@@ -949,7 -921,6 +949,7 @@@ The message to output sub message { my $self = shift; + return if $self->silent; my ($string) = @_; chomp ($string);