Term-ProgressBar-2.14/0000755000175000017500000000000012172734661013555 5ustar gaborgaborTerm-ProgressBar-2.14/Changes0000644000175000017500000000605312172734544015054 0ustar gaborgaborRevision history for Perl extension Term-ProgressBar. 2.14 Sun Jul 21 13:34:52 2013 - Document the term_width argument to the constructor (OVID) - Add a "silent" option to the constructor (OVID) 2.13 Fri May 18 06:24:42 2012 - remove unused and invalid SIGNATURE file - move content of BUGS to Changes - Remove the INSTALL and configure files, people should use the standard CPAN installation tools - Add standard prerequisites to Makefile.PL 2.12 Wed May 16 12:47:16 2012 - use strict; use warnings; in examples - remove bareword from POD (JBAKER) - make lbrack and rbrack official. 2.11 Fri Feb 17 12:31:04 2012 - skip the signature verification 2.10 Wed Dec 21 11:18:26 2011 - remove Build.PL (keep the Makefile.PL only) - Replace home-made testing tools with CPAN-ish tools - Require Capture::Tiny for testing - New co-maintainer: Gabor Szabo 2.09 Sun Mar 13 9:17 PM GMT 2005 - Fix for incorrect formatting of 'D...' time done at end 2.08 Sat Mar 12 11:47 AM GMT 2005 - Add remove option - Add patch to account for weird terminal sizing under Windoze (thanks to Andrew Peters for the patch). 2.07 Sun Mar 6 1:31 PM GMT 2005 - Correct handling of non-term mode to output stats but no PB - Print time taken to complete in ETA mode when Done - Add use of 'name' to example in 'new' doc - Add doc of use of minor characters to description - Add doc. for name value to new 2.06 Sun Mar 14 10:46 AM GMT 2004 - Add patch to cope when terminal size cannot be detected or is too small. Thanks to Ed Avis () for the patch. - Add patch to test to avoid failure on windoze due to unlinking open files - Add patch to cope when Term::ReadKey fails to initialize for some reason. Thanks to Scott Cain () for the patch. - Add patch to suppress unnecessary terminal updates Thanks to Ed Avis () for the patch. 2.05 Sat Aug 30 4:23 PM GMT 2003 - Fix test.pm to handle OS (e.g., Solaris) who refuse to delete the cwd 2.04 Sat Aug 14 4:38 PM GMT 2003 - Change build system to accomodate CPAN & automated tests 2.03 Sat Jan 11 3:47 PM GMT 2003 - Fix incorrect reset of progress bar in message method Thanks to Frank Maas () for the patch. - Improve documentation of ETA display formats. 2.02 Tue Nov 19 10:08 PM GMT 2002 - Fix behaviour in terminals where GetTerminalSize fails (e.g., resized Emacs term windows). Thanks to Ed Avis for the patch. 2.01 Mon Oct 7 9:12 PM GMT 2002 - Make it 5.005_03-compatible, with thanks to Ed Avis 2.00 Sun Mar 10 5:26 AM GMT 2002 - New API added; now takes one hashref as argument (see docs) - v1 API remains, but is deprecated - Add message method to Term::ProgressBar - Add v2 tests 1.51 Sun Dec 2 12:22 PM GMT 2001 - Correct Bug #001 Wrong minor character (= should be *) selected by default. 1.50 Sat Dec 1 1:11 PM GMT 2001 - Merged with Utility::Progress by Martyn J. Pearce 1.00 Mon Oct 30 2001 - original version - by Edward Avis, Term-ProgressBar-2.14/README0000644000175000017500000000155611755341112014433 0ustar gaborgaborModule Term-ProgressBar (2.09): Description: A progress bar for things that take a while. It looks like 50% [===== ] and is as long as the terminal. Linear estimation of the time left for the process to run is available. Modules & Classes Provided: Term::ProgressBar - provide a progress meter on a standard terminal Required Packages: Class::MethodMaker 1.02 Term::ReadKey 2.14 Required Perl Version: 5.006 Package Maintainer: Martyn J. Pearce fluffy@cpan.org Copyright: Copyright (c) 2005, 2004, 2003, 2002, 2001 Martyn J. Pearce. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (c) 2000 Ed Avis. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. 13th March, 2005 Term-ProgressBar-2.14/MANIFEST0000644000175000017500000000065712172734661014716 0ustar gaborgaborChanges examples/powers examples/powers2 examples/powers3 examples/powers4 examples/powers5 examples/simple_use.pl examples/smooth_bar.pl lib/Term/ProgressBar.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml README t/compat.t t/eta-linear.t t/name.t t/silent.t t/v1-message.t t/v2-message.t t/v2-mobile.t t/v2-simple.t t/zero.t META.json Module JSON meta-data (added by MakeMaker) Term-ProgressBar-2.14/examples/0000755000175000017500000000000012172734661015373 5ustar gaborgaborTerm-ProgressBar-2.14/examples/powers30000644000175000017500000000077511754667065016741 0ustar gaborgabor#!/usr/bin/perl use strict; use warnings; use Term::ProgressBar 2.00; use constant MAX => 100_000; my $max = int($ARGV[0] || MAX); my $progress = Term::ProgressBar->new({ name => 'Powers', count => $max, remove => 3, }); $progress->minor(0); my $next_update = 0; for (0..$max) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { $is_power = 1 if 2**$i == $_; } $next_update = $progress->update($_) if $_ > $next_update; } $progress->update($max) if $max >= $next_update; Term-ProgressBar-2.14/examples/smooth_bar.pl0000644000175000017500000000046311674321523020063 0ustar gaborgabor#!/usr/bin/perl use strict; use warnings; use Term::ProgressBar 2.00; my $max = shift || 100; my $progress = Term::ProgressBar->new($max); for (0..$max) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { $is_power = 1 if 2**$i == $_; } $progress->update($_) } Term-ProgressBar-2.14/examples/powers20000644000175000017500000000050611754666761016732 0ustar gaborgabor#!/usr/bin/perl use strict; use warnings; use Term::ProgressBar 2.00; use constant MAX => 100_000; my $max = int($ARGV[0] || MAX); my $progress = Term::ProgressBar->new($max); for (0..$max) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { $is_power = 1 if 2**$i == $_; } $progress->update($_); } Term-ProgressBar-2.14/examples/powers50000644000175000017500000000114211754666627016733 0ustar gaborgabor#!/usr/bin/perl use strict; use warnings; use Term::ProgressBar 2.00; use constant MAX => 10_000_000; my $max = int($ARGV[0]+0) || MAX; my $progress = Term::ProgressBar->new({ name => 'Powers', count => $max, ETA => 'linear', }); $progress->max_update_rate(1); my $next_update = 0; for (0..$max) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { if ( 2**$i == $_ ) { $is_power = 1; $progress->message(sprintf "Found %8d to be 2 ** %2d", $_, $i); } } $next_update = $progress->update($_) if $_ > $next_update; } $progress->update($max) if $max >= $next_update; Term-ProgressBar-2.14/examples/simple_use.pl0000644000175000017500000000052411674321523020071 0ustar gaborgabor#!/usr/bin/perl use strict; use warnings; use Term::ProgressBar 2.00; use constant MAX => 100_000; my $progress = Term::ProgressBar->new(MAX); for (0..MAX) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { $is_power = 1 if 2**$i == $_; } if ( $is_power ) { $progress->update($_); } } Term-ProgressBar-2.14/examples/powers0000644000175000017500000000054311754673060016637 0ustar gaborgabor#!/usr/bin/perl use strict; use warnings; use Term::ProgressBar 2.00; use constant MAX => 100_000; my $max = int($ARGV[0]+0) || MAX; my $progress = Term::ProgressBar->new($max); for (0..$max) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { $is_power = 1 if 2**$i == $_; } if ( $is_power ) { $progress->update($_); } } Term-ProgressBar-2.14/examples/powers40000644000175000017500000000103411754667151016723 0ustar gaborgabor#!/usr/bin/perl use strict; use warnings; use Term::ProgressBar 2.00; use constant MAX => 1_000_000; my $max = int($ARGV[0] || MAX); my $progress = Term::ProgressBar->new({ name => 'Powers', count => $max, ETA => 'linear', }); #$progress->minor(0); my $next_update = 0; for (0..$max) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { $is_power = 1 if 2**$i == $_; } sleep 1 if $_ % 4 == 0; $next_update = $progress->update($_) if $_ > $next_update; } $progress->update($max) if $max >= $next_update; Term-ProgressBar-2.14/Makefile.PL0000644000175000017500000000141511755343621015526 0ustar gaborgaborrequire 5.006; use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile ( NAME => 'Term::ProgressBar', VERSION_FROM => 'lib/Term/ProgressBar.pm', ABSTRACT_FROM => 'lib/Term/ProgressBar.pm', AUTHOR => 'Martyn J. Pearce', LICENSE => 'perl', PREREQ_PM => { 'Class::MethodMaker' => '1.02', 'Term::ReadKey' => '2.14', 'Carp' => 0, 'Fatal' => 0, 'POSIX' => 0, }, BUILD_REQUIRES => { 'Capture::Tiny' => '0.13', 'Test::More' => '0.80', 'Test::Exception' => '0.31', 'File::Temp' => 0, }, META_MERGE => { resources => { repository => 'https://github.com/szabgab/Term-ProgressBar', }, }, ); Term-ProgressBar-2.14/MANIFEST.SKIP0000644000175000017500000000025611754666150015460 0ustar gaborgabor^(.*/)?CVS/.* ^.git ^Makefile(.old)?$ ^Build$ ^Clean$ ^RollingBuild$ ^blib/.* ^pm_to_blib$ ^(.*/)?.cvsignore$ ^MANIFEST.bak$ ^*~$ ^make[-.]pm$ ^INFO.yaml$ ^_build/ ^MYMETA.* Term-ProgressBar-2.14/lib/0000755000175000017500000000000012172734661014323 5ustar gaborgaborTerm-ProgressBar-2.14/lib/Term/0000755000175000017500000000000012172734661015232 5ustar gaborgaborTerm-ProgressBar-2.14/lib/Term/ProgressBar.pm0000644000175000017500000006713712172734440020032 0ustar gaborgaborpackage Term::ProgressBar; #XXX TODO Redo original test with count=20 # Amount Output # Amount Prefix/Suffix # Tinker with $0? # Test use of last_update (with update(*undef*)) with scales # Choice of FH other than STDERR # If no term, output no progress bar; just progress so far # Use of simple term with v2.0 bar # If name is wider than term, trim name # Don't update progress bar on new? =head1 NAME Term::ProgressBar - provide a progress meter on a standard terminal =head1 SYNOPSIS use Term::ProgressBar; $progress = Term::ProgressBar->new ({count => $count}); $progress->update ($so_far); =head1 DESCRIPTION Term::ProgressBar provides a simple progress bar on the terminal, to let the user know that something is happening, roughly how much stuff has been done, and maybe an estimate at how long remains. A typical use sets up the progress bar with a number of items to do, and then 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 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. Remember to call the C<< $progress->update($max_value) >> when the job is done to get a nice 100% done bar. A progress bar by default is simple; it just goes from left-to-right, filling the bar with '=' characters. These are called B characters. For long-running jobs, this may be too slow, so two additional features are available: a linear completion time estimator, and/or a B character: this is a character that I from left-to-right on the progress bar (it does not fill it as the major character does), traversing once for each major-character added. This exponentially increases the granularity of the bar for the same width. =head1 EXAMPLES =head2 A really simple use #!/usr/bin/perl use Term::ProgressBar 2.00; use constant MAX => 100_000; my $progress = Term::ProgressBar->new(MAX); for (0..MAX) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { $is_power = 1 if 2**$i == $_; } if ( $is_power ) { $progress->update($_); } } see eg/simle_use.pl Here is a simple example. The process considers all the numbers between 0 and MAX, and updates the progress bar whenever it finds one. Note that the progress bar update will be very erratic. See below for a smoother example. Note also that the progress bar will never complete; see below to solve this. The complete text of this example is in F in the distribution set (it is not installed as part of the module). =head2 A smoother bar update my $progress = Term::ProgressBar->new($max); for (0..$max) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { $is_power = 1 if 2**$i == $_; } $progress->update($_) } See eg/smooth_bar.pl This example calls update for each value considered. This will result in a much smoother progress update, but more program time is spent updating the bar than doing the "real" work. See below to remedy this. This example does I call C<< $progress->update($max); >> at the end, since it is unnecessary, and ProgressBar will throw an exception at an attempt to update a finished bar. The complete text of this example is in F in the distribution set (it is not installed as part of the module. =head2 A (much) more efficient update my $progress = Term::ProgressBar->new({name => 'Powers', count => $max, remove => 1}); $progress->minor(0); my $next_update = 0; for (0..$max) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { $is_power = 1 if 2**$i == $_; } $next_update = $progress->update($_) if $_ >= $next_update; } $progress->update($max) if $max >= $next_update; This example does two things to improve efficiency: firstly, it uses the value returned by L to only call it again when needed; secondly, it switches off the use of minor characters to update a lot less frequently (C<< $progress->minor(0); >>. The use of the return value of L means that the call of C<< $progress->update($max); >> at the end is required to ensure that the bar ends on 100%, which gives the user a nice feeling. This example also sets the name of the progress bar. This example also demonstrates the use of the 'remove' flag, which removes the progress bar from the terminal when done. The complete text of this example is in F in the distribution set (it is not installed as part of the module. =head2 Using Completion Time Estimation my $progress = Term::ProgressBar->new({name => 'Powers', count => $max, ETA => 'linear', }); $progress->max_update_rate(1); my $next_update = 0; for (0..$max) { my $is_power = 0; for(my $i = 0; 2**$i <= $_; $i++) { if ( 2**$i == $_ ) { $is_power = 1; $progress->message(sprintf "Found %8d to be 2 ** %2d", $_, $i); } } $next_update = $progress->update($_) if $_ > $next_update; } $progress->update($max) if $max >= $next_update; This example uses the L option to switch on completion estimation. Also, the update return is tuned to try to update the bar approximately once per second, with the L call. See the documentation for the L method for details of the format(s) used. This example also provides an example of the use of the L function to output messages to the same filehandle whilst keeping the progress bar intact The complete text of this example is in F in the distribution set (it is not installed as part of the module. =cut # ---------------------------------------------------------------------- # Pragmas -------------------------- use strict; # Inheritance ---------------------- use base qw( Exporter ); use vars '@EXPORT_OK'; @EXPORT_OK = qw( $PACKAGE $VERSION ); # Utility -------------------------- use Carp qw( croak ); use Class::MethodMaker 1.02 qw( ); use Fatal qw( open sysopen close seek ); use POSIX qw( ceil strftime ); # ---------------------------------------------------------------------- # CLASS METHODS -------------------------------------------------------- # ---------------------------------- # CLASS CONSTANTS # ---------------------------------- =head1 CLASS CONSTANTS Z<> =cut use constant MINUTE => 60; use constant HOUR => 60 * MINUTE; use constant DAY => 24 * HOUR; # The point past which to give ETA of just date, rather than time use constant ETA_DATE_CUTOFF => 3 * DAY; # The point past which to give ETA of time, rather time left use constant ETA_TIME_CUTOFF => 10 * MINUTE; # The ratio prior to which to not dare any estimates use constant PREDICT_RATIO => 0.01; use constant DEFAULTS => { lbrack => '[', rbrack => ']', minor_char => '*', major_char => '=', fh => \*STDERR, name => undef, ETA => undef, max_update_rate => 0.5, # The following defaults are never used, but the keys # are valuable for error checking count => undef, bar_width => undef, term_width => undef, term => undef, remove => 0, silent => 0, }; use constant ETA_TYPES => { map { $_ => 1 } qw( linear ) }; use constant ALREADY_FINISHED => 'progress bar already finished'; use constant DEBUG => 0; # ------------------------------------- use vars qw($PACKAGE $VERSION); $PACKAGE = 'Term-ProgressBar'; $VERSION = '2.14'; # ---------------------------------- # CLASS CONSTRUCTION # ---------------------------------- # ---------------------------------- # CLASS COMPONENTS # ---------------------------------- # This is here to allow testing to redirect away from the terminal but still # see terminal output, IYSWIM my $__FORCE_TERM = 0; # ---------------------------------- # CLASS HIGHER-LEVEL FUNCTIONS # ---------------------------------- # ---------------------------------- # CLASS HIGHER-LEVEL PROCEDURES # ---------------------------------- sub __force_term { my $class = shift; ($__FORCE_TERM) = @_; } # ---------------------------------- # CLASS UTILITY FUNCTIONS # ---------------------------------- sub term_size { my ( $self, $fh ) = @_; return if $self->silent; eval { require Term::ReadKey; }; if ($@) { warn "Guessing terminal width due to problem with Term::ReadKey\n"; return 50; } my $result; eval { $result = (Term::ReadKey::GetTerminalSize($fh))[0]; $result-- if ($^O eq "MSWin32"); }; if ( $@ ) { warn "error from Term::ReadKey::GetTerminalSize(): $@"; } # If GetTerminalSize() failed it should (according to its docs) # return an empty list. It doesn't - that's why we have the eval {} # above - but also it may appear to succeed and return a width of # zero. # if ( ! $result ) { $result = 50; warn "guessing terminal width $result\n"; } return $result; } # INSTANCE METHODS ----------------------------------------------------- # ---------------------------------- # INSTANCE CONSTRUCTION # ---------------------------------- =head1 INSTANCE CONSTRUCTION Z<> =cut # Don't document hash keys until tested that the give the desired affect! =head2 new Create & return a new Term::ProgressBar instance. =over 4 =item ARGUMENTS If one argument is provided, and it is a hashref, then the hash is treated as a set of key/value pairs, with the following keys; otherwise, it is treated as a number, being equivalent to the C key. =over 4 =item count The item count. The progress is marked at 100% when update I is invoked, and proportionally until then. =item name A name to prefix the progress bar with. =item fh The filehandle to output to. Defaults to stderr. Do not try to use *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 printed on the RHS (once sufficient updates have been performed to make such an estimation feasible). Naturally, this is an I; no guarantees are made. The format of the estimate Note that the format is intended to be as compact as possible while giving over the relevant information. Depending upon the time remaining, the format is selected to provide some resolution whilst remaining compact. Since the time remaining decreases, the format typically changes over time. As the ETA approaches, the format will state minutes & seconds left. This is identifiable by the word C<'Left'> at the RHS of the line. If the ETA is further away, then an estimate time of completion (rather than time left) is given, and is identifiable by C<'ETA'> at the LHS of the ETA box (on the right of the progress bar). A time or date may be presented; these are of the form of a 24 hour clock, e.g. C<'13:33'>, a time plus days (e.g., C<' 7PM+3'> for around in over 3 days time) or a day/date, e.g. C<' 1Jan'> or C<'27Feb'>. If ETA is switched on, the return value of L is also affected: the idea here is that if the progress bar seems to be moving quicker than the eye would normally care for (and thus a great deal of time is spent doing progress updates rather than "real" work), the next value is increased to slow it. The maximum rate aimed for is tunable via the L component. The available values for this are: =over 4 =item undef Do not do estimation. The default. =item linear Perform linear estimation. This is simply that the amount of time between the creation of the progress bar and now is divided by the current amount done, and completion estimated linearly. =back =back =item EXAMPLES my $progress = Term::ProgressBar->new(100); # count from 1 to 100 my $progress = Term::ProgressBar->new({ count => 100 }); # same # Count to 200 thingies, outputting to stdout instead of stderr, # prefix bar with 'thingy' my $progress = Term::ProgressBar->new({ count => 200, fh => \*STDOUT, name => 'thingy' }); =back =cut Class::MethodMaker->import (new_with_init => 'new', new_hash_init => 'hash_init',); 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', silent => 0,}) if @_ == 2; my $target; croak sprintf("Term::ProgressBar::new We don't handle this many arguments: %d", scalar @_) if @_ != 1; my %config; if ( UNIVERSAL::isa ($_[0], 'HASH') ) { ($target) = @{$_[0]}{qw(count)}; %config = %{$_[0]}; # Copy in, so later playing does not tinker externally } else { ($target) = @_; } if ( my @bad = grep ! exists DEFAULTS->{$_}, keys %config ) { croak sprintf("Input parameters (%s) to %s not recognized\n", join(':', @bad), 'Term::ProgressBar::new'); } croak "Target count required for Term::ProgressBar new\n" unless defined $target; $config{$_} = DEFAULTS->{$_} for grep ! exists $config{$_}, keys %{DEFAULTS()}; delete $config{count}; $config{term} = -t $config{fh} unless defined $config{term}; if ( $__FORCE_TERM ) { $config{term} = 1; $config{term_width} = $__FORCE_TERM; 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} = $self->term_size($config{fh}); die if $config{term_width} < 5; } unless ( defined $config{bar_width} ) { if ( defined $config{term_width} ) { # 5 for the % marker $config{bar_width} = $config{term_width} - 5; $config{bar_width} -= $_ for map(( defined $config{$_} ? length($config{$_}) : 0), qw( lbrack rbrack name )); $config{bar_width} -= 2 # Extra for ': ' if defined $config{name}; $config{bar_width} -= 10 if defined $config{ETA}; if ( $config{bar_width} < 1 ) { warn "terminal width $config{term_width} too small for bar; defaulting to 10\n"; $config{bar_width} = 10; } # } elsif ( ! $config{term} ) { # $config{bar_width} = 1; # $config{term_width} = defined $config{ETA} ? 12 : 5; } else { $config{bar_width} = $target; die "configured bar_width $config{bar_width} < 1" if $config{bar_width} < 1; } } $config{start} = time; select(((select $config{fh}), $| = 1)[0]); $self->ETA(delete $config{ETA}); $self->hash_init (%config, offset => 0, scale => 1, last_update => 0, last_position => 0, ); $self->target($target); $self->minor($config{term} && $target > $config{bar_width} ** 1.5); $self->update(0); # Initialize the progress bar } # ---------------------------------- # INSTANCE FINALIZATION # ---------------------------------- # ---------------------------------- # INSTANCE COMPONENTS # ---------------------------------- =head1 INSTANCE COMPONENTS =cut =head2 Scalar Components. See L for usage. =over 4 =item target The final target. Updates are measured in terms of this. Changes will have no effect until the next update, but the next update value should be relative to the new target. So $p = Term::ProgressBar({count => 20}); # Halfway $p->update(10); # Double scale $p->target(40) $p->update(21); will cause the progress bar to update to 52.5% =item max_update_rate This value is taken as being the maximum speed between updates to aim for. B It defaults to 0.5, being the number of seconds between updates. =back =head2 Boolean Components See L for usage. =over 4 =item minor Default: set. If unset, no minor scale will be calculated or updated. Minor characters are used on the progress bar to give the user the idea of progress even when there are so many more tasks than the terminal is wide that the granularity would be too great. By default, Term::ProgressBar makes a guess as to when minor characters would be valuable. However, it may not always guess right, so this method may be called to force it one way or the other. Of course, the efficiency saving is minimal unless the client is utilizing the return value of L. See F and F to see minor characters in action, and not in action, respectively. =back =head2 Configuration =over 4 =item lbrack Left bracket ( defaults to [ ) $progress->lbrack('<'); =item rbrack Right bracket ( defaults to ] ) $progress->rbrack('>'); =back =cut # Private Scalar Components # offset ) Default: 0. Added to any value supplied to update. # scale ) Default: 1. Any value supplied to update is multiplied by # this. # major_char) Default: '='. The character printed for the major scale. # minor_char) Default: '*'. The character printed for the minor scale. # name ) Default: undef. The name to print to the side of the bar. # fh ) Default: STDERR. The filehandle to output progress to. # Private Counter Components # last_update ) Default: 0. The so_far value last time update was invoked. # last_position) Default: 0. The number of the last progress mark printed. # Private Boolean Components # term ) Default: detected (by C). # If unset, we assume that we are not connected to a terminal (or # at least, not a suitably intelligent one). Then, we attempt # minimal functionality. Class::MethodMaker->import ( get_set => [qw/ major_units major_char minor_units minor_char lbrack rbrack name offset scale fh start max_update_rate silent /], counter => [qw/ last_position last_update /], boolean => [qw/ minor name_printed pb_ended remove /], # let it be boolean to handle 0 but true get_set => [qw/ term /], ); # 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; $self->{bar_width} = $_[0]; } 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; $self->{term_width} = $_[0]; } sub target { my $self = shift; return if $self->silent; if ( @_ ) { my ($target) = @_; if ( $target ) { $self->major_units($self->bar_width / $target); $self->minor_units($self->bar_width ** 2 / $target); $self->minor ( defined $self->term_width and $self->term_width < $target ); } $self->{target} = $target; } return $self->{target}; } sub ETA { my $self = shift; return if $self->silent; if (@_) { my ($type) = @_; croak "Invalid ETA type: $type\n" if defined $type and ! exists ETA_TYPES->{$type}; $self->{ETA} = $type; } return $self->{ETA}; } # ---------------------------------- # INSTANCE HIGHER-LEVEL FUNCTIONS # ---------------------------------- # ---------------------------------- # INSTANCE HIGHER-LEVEL PROCEDURES # ---------------------------------- =head1 INSTANCE HIGHER-LEVEL PROCEDURES Z<> =cut sub no_minor { warn sprintf("%s: This method is deprecated. Please use %s instead\n", (caller (0))[3], '$x->minor (0)',); $_[0]->clear_minor (0); } # ------------------------------------- =head2 update Update the progress bar. =over 4 =item ARGUMENTS =over 4 =item so_far Current progress point, in whatever units were passed to C. If not defined, assumed to be 1+ whatever was the value last time C was called (starting at 0). =back =item RETURNS =over 4 =item next_call The next value of so_far at which to call C. =back =back =cut sub update { my $self = shift; return if $self->silent; my ($so_far) = @_; if ( ! defined $so_far ) { $so_far = $self->last_update + 1; } my $input_so_far = $so_far; $so_far *= $self->scale unless $self->scale == 1; $so_far += $self->offset; my $target = my $next = $self->target; my $name = $self->name; my $fh = $self->fh; if ( $target < 1 ) { print $fh "\r"; printf $fh "$name: " if defined $name; print $fh "(nothing to do)\n"; return 2**32-1; } my $biggies = $self->major_units * $so_far; my @chars = (' ') x $self->bar_width; $chars[$_] = $self->major_char for 0..$biggies-1; if ( $self->minor ) { my $smally = $self->minor_units * $so_far % $self->bar_width; $chars[$smally] = $self->minor_char unless $so_far == $target; $next *= ($self->minor_units * $so_far + 1) / ($self->bar_width ** 2); } else { $next *= ($self->major_units * $so_far + 1) / $self->bar_width; } local $\ = undef; if ( $self->term > 0 ) { local $\ = undef; my $to_print = "\r"; $to_print .= "$name: " if defined $name; my $ratio = $so_far / $target; # Rounds down % $to_print .= (sprintf ("%3d%% %s%s%s", $ratio * 100, $self->lbrack, join ('', @chars), $self->rbrack)); my $ETA = $self->ETA; if ( defined $ETA and $ratio > 0 ) { if ( $ETA eq 'linear' ) { if ( $ratio == 1 ) { my $taken = time - $self->start; my $ss = $taken % 60; my $mm = int(($taken % 3600) / 60); my $hh = int($taken / 3600); if ( $hh > 99 ) { $to_print .= sprintf('D %2dh%02dm', $hh, $mm, $ss); } else { $to_print .= sprintf('D%2dh%02dm%02ds', $hh, $mm, $ss); } } elsif ( $ratio < PREDICT_RATIO ) { # No safe prediction yet $to_print .= 'ETA ------'; } else { my $time = time; my $left = (($time - $self->start) * ((1 - $ratio) / $ratio)); if ( $left < ETA_TIME_CUTOFF ) { $to_print .= sprintf '%1dm%02ds Left', int($left / 60), $left % 60; } else { my $eta = $time + $left; my $format; if ( $left < DAY ) { $format = 'ETA %H:%M'; } elsif ( $left < ETA_DATE_CUTOFF ) { $format = sprintf('ETA %%l%%p+%d',$left/DAY); } else { $format = 'ETA %e%b'; } $to_print .= strftime($format, localtime $eta); } # Calculate next to be at least SEC_PER_UPDATE seconds away if ( $left > 0 ) { my $incr = ($target - $so_far) / ($left / $self->max_update_rate); $next = $so_far + $incr if $so_far + $incr > $next; } } } else { croak "Bad ETA type: $ETA\n"; } } for ($self->{last_printed}) { unless (defined and $_ eq $to_print) { print $fh $to_print; } $_ = $to_print; } $next -= $self->offset; $next /= $self->scale unless $self->scale == 1; if ( $so_far >= $target and $self->remove and ! $self->pb_ended) { print $fh "\r", ' ' x $self->term_width, "\r"; $self->pb_ended; } } else { local $\ = undef; if ( $self->term ) { # special case for backwards compat. if ( $so_far == 0 and defined $name and ! $self->name_printed ) { print $fh "$name: "; $self->set_name_printed; } my $position = int($self->bar_width * ($input_so_far / $target)); my $add = $position - $self->last_position; $self->last_position_incr ($add) if $add; print $fh $self->major_char x $add; $next -= $self->offset; $next /= $self->scale unless $self->scale == 1; } else { my $pc = int(100*$input_so_far/$target); printf $fh "[%s] %s: %3d%%\n", scalar(localtime), $name, $pc; $next = ceil($target * ($pc+1)/100); } if ( $input_so_far >= $target ) { if ( $self->pb_ended ) { croak ALREADY_FINISHED; } else { if ( $self->term ) { print $fh "\n" } $self->set_pb_ended; } } } $next = $target if $next > $target; $self->last_update($input_so_far); return $next; } # ------------------------------------- =head2 message Output a message. This is very much like print, but we try not to disturb the terminal. =over 4 =item ARGUMENTS =over 4 =item string The message to output. =back =back =cut sub message { my $self = shift; return if $self->silent; my ($string) = @_; chomp ($string); my $fh = $self->fh; local $\ = undef; if ( $self->term ) { print $fh "\r", ' ' x $self->term_width; print $fh "\r$string\n"; } else { print $fh "\n$string\n"; print $fh $self->major_char x $self->last_position; } undef $self->{last_printed}; $self->update($self->last_update); } # ---------------------------------------------------------------------- =head1 REPORTING BUGS via RT: L =head1 COMPATIBILITY If exactly two arguments are provided, then L operates in v1 compatibility mode: the arguments are considered to be name, and item count. Various other defaults are set to emulate version one (e.g., the major output character is '#', the bar width is set to 50 characters and the output filehandle is not treated as a terminal). This mode is deprecated. =head1 AUTHOR Martyn J. Pearce fluffy@cpan.org Significant contributions from Ed Avis, amongst others. =head1 MAINTAINER Gabor Szabo L =head1 COPYRIGHT Copyright (c) 2001, 2002, 2003, 2004, 2005 Martyn J. Pearce. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # keep require happy. __END__ Term-ProgressBar-2.14/t/0000755000175000017500000000000012172734661014020 5ustar gaborgaborTerm-ProgressBar-2.14/t/compat.t0000644000175000017500000000250611666070251015466 0ustar gaborgabor# (X)Emacs mode: -*- cperl -*- use strict; use warnings; =head1 Unit Test Package for Term::ProgressBar v1.0 Compatibility This script is based on the test script for Term::ProgressBar version 1.0, and is intended to test compatibility with that version. =cut # Utility ----------------------------- use Test::More tests => 9; use Term::ProgressBar; use POSIX qw; use Capture::Tiny qw(capture); $| = 1; my $count = 100; diag 'create a bar'; my $test_str = 'test'; my $tp; { my ($out, $err) = capture { $tp = Term::ProgressBar->new($test_str, $count); }; isa_ok $tp, 'Term::ProgressBar'; is $out, '', 'empty stdout'; is $err, "$test_str: "; } diag 'do half the stuff and check half the bar has printed'; my $halfway = floor($count / 2); { my ($out, $err) = capture { $tp->update foreach (0 .. $halfway - 1) }; is $out, '', 'empty stdout'; is $err, ('#' x floor(50 / 2)); } # do the rest of the stuff and check the whole bar has printed { my ($out, $err) = capture { $tp->update foreach ($halfway .. $count - 1) }; is $out, '', 'empty stdout'; is $err, ('#' x ceil(50 / 2)) . "\n"; } # try to do another item and check there is an error eval { $tp->update }; my $err = $@; ok defined($err); is substr($err, 0, length(Term::ProgressBar::ALREADY_FINISHED)), Term::ProgressBar::ALREADY_FINISHED; Term-ProgressBar-2.14/t/name.t0000644000175000017500000000754511666071053015134 0ustar gaborgabor# (X)Emacs mode: -*- cperl -*- use strict; use warnings; =head1 Unit Test Package for Term::ProgressBar This package tests the name functionality of Term::ProgressBar. =cut use Test::More tests => 20; use Test::Exception; use Capture::Tiny qw(capture_stderr); my $MESSAGE1 = 'The Gospel of St. Jude'; my $NAME1 = 'Algenon'; my $NAME2 = 'Smegma'; use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); # ------------------------------------- =head2 Tests 2--10: Count 1-10 Create a progress bar with 10 things, and a name 'Algenon'. Update it it from 1 to 10. (1) Check no exception thrown on creation (2) Check no exception thrown on update (1..3) (3) Check bar number is 30% (4) Check bar is 30% along (5) Check no exception thrown on message send (6) Check no exception thrown on update (6..10) (7) Check message seen (8) Check bar is complete (9) Check bar number is 100% =cut { my $p; my $err = capture_stderr { lives_ok { $p = Term::ProgressBar->new({count => 10, name => $NAME1}); } 'Count 1-10 ( 1)'; lives_ok { $p->update($_) for 1..3 } 'Count 1-10 ( 2)'; }; $err =~ s!^.*\r!!gm; diag "ERR (1) :\n$err\nlength: " . length($err) if $ENV{TEST_DEBUG}; my @lines = split /\n/, $err; like $lines[-1], qr/^@{[$NAME1]}: \s*\b30%/, 'Count 1-10 ( 3)'; my ($bar, $space) = $lines[-1] =~ /\[(=*)(\s*)\]/; my $length = length($bar) + length($space); print STDERR ("LENGTHS (1) :BAR:", length($bar), ":SPACE:", length($space), "\n") if $ENV{TEST_DEBUG}; my $barexpect = $length * 0.3; cmp_ok length($bar), '>', $barexpect -1; cmp_ok length($bar), '<', $barexpect+1; $err = capture_stderr { lives_ok { $p->message($MESSAGE1) } 'Count 1-10 ( 5)'; lives_ok { $p->update($_) for 6..10 } 'Count 1-10 ( 6)'; }; $err =~ s!^.*\r!!gm; diag "ERR (2) :\n$err\nlength: " . length($err) if $ENV{TEST_DEBUG}; @lines = split /\n/, $err; is $lines[0], $MESSAGE1, 'Count 1-10 ( 7)'; like $lines[-1], qr/\[=+\]/, 'Count 1-10 ( 8)'; like $lines[-1], qr/^@{[$NAME1]}: \s*100%/, 'Count 1-10 ( 9)'; } # ------------------------------------- =head2 Tests 11--20: Count 1-20 Create a progress bar with 20 things, and a name 'Smegma'. Update it it from 1 to 20. Use v1 mode (1) Check no exception thrown on creation (2) Check no exception thrown on update (1..12) (3) Check bar number is 60% (4) Check bar is 60% along (5) Check no exception thrown on message send (6) Check no exception thrown on update (13..20) (7) Check message seen (8) Check bar is complete (9) Check bar number is 100% =cut { my $p; my $err = capture_stderr { lives_ok { $p = Term::ProgressBar->new($NAME2, 10); } 'Count 1-10 ( 1)'; lives_ok { $p->update($_) for 1..3 } 'Count 1-10 ( 2)'; }; $err =~ s!^.*\r!!gm; diag "ERR (1) :\n$err\nlength: " . length($err) if $ENV{TEST_DEBUG}; my @lines = split /\n/, $err; like $lines[-1], qr/^@{[$NAME2]}: \s*\b30%/, 'Count 1-10 ( 3)'; my ($bar, $space) = $lines[-1] =~ /(\#*)(\s*)/; my $length = length($bar) + length($space); diag ("LENGTHS (1) :BAR:" . length($bar) . ":SPACE:" . length($space)) if $ENV{TEST_DEBUG}; my $barexpect = $length * 0.3; cmp_ok length($bar), '>', $barexpect -1; cmp_ok length($bar), '<', $barexpect+1; $err = capture_stderr { lives_ok { $p->message($MESSAGE1) } 'Count 1-10 ( 5)'; lives_ok { $p->update($_) for 6..10 } 'Count 1-10 ( 6)'; }; $err =~ s!^.*\r!!gm; diag "ERR (2) :\n$err\nlength: " . length($err) if $ENV{TEST_DEBUG}; @lines = split /\n/, $err; like $lines[-1], qr/^@{[$NAME2]}: \s*\d+% \#*$/, 'Count 1-10 ( 8)'; like $lines[-1], qr/^@{[$NAME2]}: \s*100%/, 'Count 1-10 ( 9)'; } # ------------------------------------- Term-ProgressBar-2.14/t/v2-message.t0000644000175000017500000000451111666070610016151 0ustar gaborgabor# (X)Emacs mode: -*- cperl -*- use strict; use warnings; =head1 Unit Test Package for Term::ProgressBar This package tests the basic functionality of Term::ProgressBar. =cut use Test::More tests => 11; use Test::Exception; use Capture::Tiny qw(capture_stderr); my $MESSAGE1 = 'Walking on the Milky Way'; =head2 Test 1: compilation This test confirms that the test script and the modules it calls compiled successfully. =cut use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); # ------------------------------------- =head2 Tests 2--8: Count 1-10 Create a progress bar with 10 things. Update it it from 1 to 10. Output a message halfway through. (1) Check no exception thrown on creation (2) Check no exception thrown on update (1..5) (3) Check no exception thrown on message send (4) Check no exception thrown on update (6..10) (5) Check message was issued. (6) Check bar is complete (7) Check bar number is 100% =cut { my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)'; lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)'; lives_ok { $p->message($MESSAGE1) } 'Count 1-10 (3)'; lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)'; }; $err =~ s!^.*\r!!gm; diag "ERR:\n$err\nlength: " . length($err) if $ENV{TEST_DEBUG}; my @lines = split /\n/, $err; is $lines[0], $MESSAGE1; like $lines[-1], qr/\[=+\]/, 'Count 1-10 (5)'; like $lines[-1], qr/^\s*100%/, 'Count 1-10 (6)'; } # ------------------------------------- =head2 Tests 9--11: Message Check Run a progress bar from 0 to 100, each time calling a message after an update. This is to check that message preserves the progress bar value correctly. ( 1) Check no exception thrown on creation ( 2) Check no exception thrown on update, message (0..100). ( 3) Check last progress is 100% =cut { my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(100); } 'Message Check ( 1)'; lives_ok { for (0..100) { $p->update($_); $p->message("Hello") } } 'Message Check ( 2)'; }; my @err_lines = split /\n/, $err; (my $last_line = $err_lines[-1]) =~ tr/\r//d; is substr($last_line, 0, 4), '100%', 'Message Check ( 3)'; } # ---------------------------------------------------------------------------- Term-ProgressBar-2.14/t/v2-simple.t0000644000175000017500000000456511666070723016034 0ustar gaborgabor# (X)Emacs mode: -*- cperl -*- use strict; use warnings; =head1 Unit Test Package for Term::ProgressBar This package tests the basic functionality of Term::ProgressBar. =cut use Test::More tests => 31; use Test::Exception; use Capture::Tiny qw(capture_stderr); use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); # ------------------------------------- =head2 Tests 2--16: Count 1-10 Create a progress bar with 10 things. Update it it from 1 to 10. (1) Check no exception thrown on creation (2) Check no exception thrown on update (3) Check bar is complete (4) Check bar number is 100% (5--15) Check bar has no minor characters at any point =cut { my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-10 (1)'; lives_ok { $p->update($_) for 1..10 } 'Count 1-10 (2)'; }; my @lines = grep {$_ ne ''} split /\r/, $err; diag explain \@lines if $ENV{TEST_DEBUG}; like $lines[-1], qr/\[=+\]/, 'Count 1-10 (3)'; like $lines[-1], qr/^\s*100%/, 'Count 1-10 (4)'; like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-10 (%d)', 5+$_) for 0..10; } # ------------------------------------- =head2 Tests 17--30: Count 1-9 Create a progress bar with 10 things. Update it it from 1 to 9. (1) Check no exception thrown on creation (2) Check no exception thrown on update (3) Check bar is incomplete (4) Check bar number is 90% (5--14) Check bar has no minor characters at any point =cut { my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-9 (1)'; lives_ok { $p->update($_) for 1..9 } 'Count 1-9 (2)'; }; my @lines = grep $_ ne '', split /\r/, $err; diag explain \@lines if $ENV{TEST_DEBUG}; like $lines[-1], qr/\[=+ +\]/, 'Count 1-9 (3)'; like $lines[-1], qr/^\s*90%/, 'Count 1-9 (4)'; like $lines[$_], qr/\[[= ]+\]/, sprintf('Count 1-9 (%d)', 5+$_) for 0..9; } # ------------------------------------- =head2 Test 31 Make sure the same progress bar text is not printed twice to the terminal (in the case of an update that is too little to affect the percentage or displayed bar). =cut { my $err = capture_stderr { my $tp = Term::ProgressBar->new(1000000); $tp->update($_) foreach (0, 1); }; my @lines = grep {$_ ne ''} split /\r/, $err; diag explain \@lines if $ENV{TEST_DEBUG}; is scalar @lines, 1; } Term-ProgressBar-2.14/t/v2-mobile.t0000644000175000017500000000242211666071117015776 0ustar gaborgabor# (X)Emacs mode: -*- cperl -*- use strict; use warnings; =head1 Unit Test Package for Term::ProgressBar This package tests the moving target functionality of Term::ProgressBar. =cut use Test::More tests => 7; use Test::Exception; use Capture::Tiny qw(capture_stderr); use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); # ------------------------------------- =head2 Tests 2--7: Count 1-20 Create a progress bar with 10 things. Update it it from 1 to 5. Change target to 20. Update it from 11 to 20. (1) Check no exception thrown on creation (2) Check no exception thrown on update (1..5) (3) Check no exception thrown on target update (4) Check no exception thrown on update (6..10) (5) Check bar is complete (6) Check bar number is 100% =cut my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new(10); } 'Count 1-20 (1)'; lives_ok { $p->update($_) for 1..5 } 'Count 1-20 (2)'; lives_ok { $p->target(20) } 'Count 1-20 (3)'; lives_ok { $p->update($_) for 11..20 } 'Count 1-20 (4)'; }; $err =~ s!^.*\r!!gm; diag "ERR:\n$err\nlength: " . length($err) if $ENV{TEST_DEBUG}; my @lines = split /\n/, $err; like $lines[-1], qr/\[=+\]/, 'Count 1-20 (5)'; like $lines[-1], qr/^\s*100%/, 'Count 1-20 (6)'; Term-ProgressBar-2.14/t/v1-message.t0000644000175000017500000000257411666070532016162 0ustar gaborgabor# (X)Emacs mode: -*- cperl -*- use strict; use warnings; =head1 Unit Test Package for Term::ProgressBar This package tests the basic functionality of Term::ProgressBar. =cut use Test::More tests => 8; use Test::Exception; use Capture::Tiny qw(capture_stderr); my $MESSAGE1 = 'Walking on the Milky Way'; use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); # ------------------------------------- =head2 Tests 2--8: Count 1-10 Create a progress bar with 10 things, and a name 'bob'. Update it it from 1 to 10. (1) Check no exception thrown on creation (2) Check no exception thrown on update (1..5) (3) Check no exception thrown on message send (4) Check no exception thrown on update (6..10) (5) Check message output. (5) Check bar is complete (6) Check bar number is 100% =cut { my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new('bob', 10); } 'Count 1-10 (1)'; lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)'; lives_ok { $p->message($MESSAGE1) } 'Count 1-10 (3)'; lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)'; }; $err =~ s!^.*\r!!gm; diag "ERR:\n$err\nlength: ", length($err) if $ENV{TEST_DEBUG}; my @lines = split /\n/, $err; is $lines[0], $MESSAGE1; like $lines[-1], qr/bob:\s+\d+% \#+/, 'Count 1-10 (6)'; like $lines[-1], qr/^bob:\s+100%/, 'Count 1-10 (7)'; } Term-ProgressBar-2.14/t/silent.t0000644000175000017500000000275212172734347015512 0ustar gaborgabor# (X)Emacs mode: -*- cperl -*- use strict; use warnings; use Term::ProgressBar; =head1 Unit Test Package for Term::ProgressBar This package tests the basic functionality of Term::ProgressBar. =cut use Test::More tests => 8; use Test::Exception; use Capture::Tiny qw(capture_stderr); my $MESSAGE1 = 'Walking on the Milky Way'; # ------------------------------------- =head2 Test Create a progress bar with 10 things. Update it it from 1 to 10. Verify that it has no output. =cut { my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new({ count => 10, silent => 1}); } 'Count 1-10 (1)'; lives_ok { $p->update($_) for 1..5 } 'Count 1-10 (2)'; lives_ok { $p->message($MESSAGE1) } 'Count 1-10 (3)'; lives_ok { $p->update($_) for 6..10 } 'Count 1-10 (4)'; }; diag "ERR:\n$err\nlength: " . length($err) if $ENV{TEST_DEBUG}; ok !$err, 'We should have no output'; } # ------------------------------------- =head2 Tests 9--11: Message Check Run a progress bar from 0 to 100, each time calling a message after an update. Check that we still have no output. =cut { my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new({ count => 100, silent => 1}); } 'Message Check ( 1)'; lives_ok { for (0..100) { $p->update($_); $p->message("Hello") } } 'Message Check ( 2)'; }; ok !$err, 'We should sill have no output'; } # ---------------------------------------------------------------------------- Term-ProgressBar-2.14/t/eta-linear.t0000644000175000017500000000333711666070422016227 0ustar gaborgabor# (X)Emacs mode: -*- cperl -*- use strict; use warnings; =head1 Unit Test Package for Term::ProgressBar This package tests the basic functionality of Term::ProgressBar. =cut use Test::More tests => 9; use Test::Exception; use Capture::Tiny qw(capture_stderr); use Term::ProgressBar; Term::ProgressBar->__force_term (50); # ------------------------------------- =head2 Tests 2--10: Count 1-10 Create a progress bar with 10 things. Invoke ETA and name on it. Update it it from 1 to 10. (1) Check no exception thrown on creation (2) Check no exception thrown on update 1..5 (3) Check no exception thrown on message issued (4) Check no exception thrown on update 6..10 (5) Check message seen (6) Check bar is complete (7) Check bar number is 100% (8) Check --DONE-- issued (9) Check estimation done =cut { my $err = capture_stderr { my $p; lives_ok { $p = Term::ProgressBar->new({count => 10, name => 'fred', ETA => 'linear'}); } 'Count 1-10 (1)'; lives_ok { for (1..5) { $p->update($_); sleep 1 } } 'Count 1-10 (2)'; lives_ok { $p->message('Hello Mum!') } 'Count 1-10 (3)'; lives_ok { for (6..10) { $p->update($_); sleep 1 } } 'Count 1-10 (4)'; }; my @lines = grep $_ ne '', split /[\n\r]+/, $err; diag explain \@lines if $ENV{TEST_DEBUG}; ok grep $_ eq 'Hello Mum!', @lines; like $lines[-1], qr/\[=+\]/, 'Count 1-10 (6)'; like $lines[-1], qr/^fred: \s*100%/, 'Count 1-10 (7)'; like $lines[-1], qr/D[ \d]\dh\d{2}m\d{2}s$/, 'Count 1-10 (8)'; like $lines[-2], qr/ Left$/, 'Count 1-10 (9)'; } # ---------------------------------------------------------------------------- Term-ProgressBar-2.14/t/zero.t0000644000175000017500000000353411666070357015173 0ustar gaborgabor# (X)Emacs mode: -*- cperl -*- use strict; use warnings; =head1 Unit Test Package for Term::ProgressBar This package tests the zero-progress handling of progress bar. =cut use Test::More tests => 9; use Test::Exception; use Capture::Tiny qw(capture_stderr); use_ok 'Term::ProgressBar'; Term::ProgressBar->__force_term (50); # ------------------------------------- =head2 Tests 2--5: V1 mode Create a progress bar with 0 things. Update it it from 1 to 10. (1) Check no exception thrown on creation (2) Check no exception thrown on update (3) Check bar displays name (3) Check bar says nothing to do =cut { my $p; my $name = 'doing nothing'; my $err = capture_stderr { lives_ok { $p = Term::ProgressBar->new($name, 0); } 'V1 mode ( 1)'; lives_ok { $p->update($_) for 1..10 } 'V1 mode ( 2)'; }; my @lines = grep { $_ ne ''} split /\r/, $err; diag explain @lines if $ENV{TEST_DEBUG}; like $lines[-1], qr/^$name:/, 'V1 mode ( 3)'; like $lines[-1], qr/\(nothing to do\)/, 'V1 mode ( 4)'; } # ------------------------------------- =head2 Tests 6--9: V2 mode Create a progress bar with 0 things. Update it it from 1 to 10. (1) Check no exception thrown on creation (2) Check no exception thrown on update (3) Check bar displays name (4) Check bar says nothing to do =cut { my $p; my $name = 'zero'; my $err = capture_stderr { lives_ok { $p = Term::ProgressBar->new({ count => 0, name => $name }); } 'V2 mode ( 1)'; lives_ok { $p->update($_) for 1..10 } 'V2 mode ( 2)'; }; my @lines = grep {$_ ne ''} split /\r/, $err; diag explain @lines if $ENV{TEST_DEBUG}; like $lines[-1], qr/^$name:/, 'V2 mode ( 3)'; like $lines[-1], qr/\(nothing to do\)/, 'V2 mode ( 4)'; } # ---------------------------------------------------------------------------- Term-ProgressBar-2.14/META.json0000664000175000017500000000232312172734661015200 0ustar gaborgabor{ "abstract" : "provide a progress meter on a standard terminal", "author" : [ "Martyn J. Pearce" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.131560", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Term-ProgressBar", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "Capture::Tiny" : "0.13", "File::Temp" : "0", "Test::Exception" : "0.31", "Test::More" : "0.80" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Class::MethodMaker" : "1.02", "Fatal" : "0", "POSIX" : "0", "Term::ReadKey" : "2.14" } } }, "release_status" : "stable", "resources" : { "repository" : { "url" : "https://github.com/szabgab/Term-ProgressBar" } }, "version" : "2.14" } Term-ProgressBar-2.14/META.yml0000664000175000017500000000125512172734661015033 0ustar gaborgabor--- abstract: 'provide a progress meter on a standard terminal' author: - 'Martyn J. Pearce' build_requires: Capture::Tiny: 0.13 File::Temp: 0 Test::Exception: 0.31 Test::More: 0.80 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.131560' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Term-ProgressBar no_index: directory: - t - inc requires: Carp: 0 Class::MethodMaker: 1.02 Fatal: 0 POSIX: 0 Term::ReadKey: 2.14 resources: repository: https://github.com/szabgab/Term-ProgressBar version: 2.14