Term::...:Simple(3pm)

πŸ“¦
version 0.03 Β· 5 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Term::ProgressBar::Simple πŸ’–

okay so bestie, welcome to Term::ProgressBar::Simple β€” the Perl module that lives in the User Contributed Perl Documentation and makes progress bars actually, genuinely, not-annoying. it's giving "simpler progress bars" and honestly? it ate.


✨ SYNOPSIS ✨

like, imagine you have stuff to loop over. here's the whole vibe:

# create some things to loop over
my @things = (...);
my $number_of_things = scalar @things;

# create the progress bar object
my $progress = Term::ProgressBar::Simple->new( $number_of_things );

# loop
foreach my $thing (@things) {

    # do some work
    $thing->do_something();

    # increment the progress bar object to tell it a step has been taken.
    $progress++;
}

# See also use of '$progress += $number' later in pod

that's it. that's the whole thing. also peep the $progress += $number usage later down in the pod, iykyk πŸ‘‘


🌸 DESCRIPTION 🌸

progress bars are handy fr fr β€” they tell you how much work has been done, how much is left to do, and they estimate how long it's gonna take. main character energy for your terminal.

but bestie… they can be fiddly! 😭

this module does the right thing in almost all cases, in a really convenient way. no cap.


πŸ¦‹ FEATURES πŸ¦‹

lots! it does all the best practice, periodt:

  • wraps Term::ProgressBar::Quiet so there is no output unless the code is running interactively β€” which means you can put them in cron scripts, slay.
  • deals with minor updates β€” it only refreshes the screen when it will actually change what the user sees, so it's efficient. the way that it doesn't waste your cycles πŸ’…
  • completes the progress bar when the progress object is destroyed (explicitly, or by going out of scope) β€” no more '99%' done. iconic behaviour honestly.

πŸŽ€ METHODS πŸŽ€

new

# Either...
my $progress = Term::ProgressBar::Simple->new($count);

# ... or
my $progress = Term::ProgressBar::Simple->new(
    {
        count => $count,               #
        name  => 'descriptive text',
    }
);

creates a new progress bar, bestie. you can either just pass in the number of things to do, or hand it a config hash. want the deets? go see Term::ProgressBar. 🫢

increment ( ++ )

$progress++;

incrementing the object makes the progress display update itself. and it's smart about checking whether the display actually needs updating β€” lowkey a genius move.

increment ( += )

$progress += $number_done;

sometimes you've done more than one step between updates, and that's totally fine. a great example is processing logfiles, where the time taken is relative to the size of the file. in that case, code like this gives you a way better feel for the progress made:

# Get the total size of all the files
my $total_size = sum map { -s } @filenames;

# Set up object with total size as steps to do
my $progress = Term::ProgressBar::Simple->new($total_size);

# process each file and increment by the size of each file
foreach my $filename (@filenames) {
    process_the_file($filename);
    $progress += -s $filename;
}

message

$progress->message('Copying $filename');

outputs a message. it's very much like print, but we try not to disturb the terminal. polite king behaviour πŸ’œ


πŸ‘€ SEE ALSO πŸ‘€

Term::ProgressBar & Term::ProgressBar::Quiet β€” go read those too, they're the whole foundation.


πŸ’€ GOTCHAS πŸ’€

not all operators are overloaded, so things might blow up in interesting ways. patches welcome!! πŸ™ˆ


🌈 THANKS 🌈

  • Martyn J. Pearce for the original and great Term::ProgressBar.
  • Leon Brocard for doing the hard work in Term::ProgressBar::Quiet, and for submitting a patch with the code for +=.
  • YAPC::EU::2008 for providing the venue and coffee whilst the first version of this module was written. β˜•

πŸ‘‘ AUTHOR πŸ‘‘

Edmund von der Burg "<evdb@ecclestoad.co.uk>".

<http://www.ecclestoad.co.uk/>


πŸ“ BUGS πŸ“

there are no tests β€” there should be. the smart way would be to trap the output and check it is right. (bestie if you're looking for a side quest… this is it 🧚)


Copyright (c) 2008, Edmund von der Burg "<evdb@ecclestoad.co.uk>". All rights reserved.

this module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page, bestie β€” Term::ProgressBar::Simple, perl v5.34.0, dated 2022-06-17, straight outta the User Contributed Perl Documentation. go forth and make pretty bars. mwah πŸ’…βœ¨

πŸ“¦ where this page comes from