Term::Pulse - show pulsed progress bar in terminal


Term-Pulse documentation Contained in the Term-Pulse distribution.

Index


Code Index:

NAME

Top

Term::Pulse - show pulsed progress bar in terminal

VERSION

Top

Version 0.03

SYNOPSIS

Top

    use Term::Pulse;
    pulse_start( name => 'Checking', rotate => 0, time => 1 ); # start the pulse
    sleep 3;
    pulse_stop()                                               # stop it

EXPORT

Top

The following functions are exported by default.

pulse_start()

pulse_stop()

FUNCTIONS

Top

pulse_start()

Use this functions to start the pulse. Accept the following arguments:

    Argument            Default
    ----------------------------
    name                'Working'
    rotate              0
    size                16
    time                0

pulse_stop()

Stop the pulse and return elapsed time

KNOWN PROBLEMS

Top

Not thread safe.

AUTHOR

Top

Yen-Liang Chen, <alec at cpan.com>

BUGS

Top

Please report any bugs or feature requests to bug-term-pulse at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Term-Pulse. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Term::Pulse




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Term-Pulse

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Term-Pulse

* CPAN Ratings

http://cpanratings.perl.org/d/Term-Pulse

* Search CPAN

http://search.cpan.org/dist/Term-Pulse

COPYRIGHT & LICENSE

Top


Term-Pulse documentation Contained in the Term-Pulse distribution.
package Term::Pulse;

use warnings;
use strict;

our $VERSION = '0.03';
our @ISA = qw(Exporter);
our @EXPORT = qw(pulse_start pulse_stop);

use Time::HiRes qw(usleep time);
require Exporter;

my $pid;
my $global_name;
my $global_start_time;
my @mark = qw(- \ | / - \ | /);
$| = 1;

sub pulse_start {
    my %args = @_;
    my $name = defined $args{name}   ? $args{name}   : 'Working';
    my $type = defined $args{rotate} ? $args{rotate} : 0;
    my $size = defined $args{size}   ? $args{size}   : 16;
    my $time = defined $args{time}   ? $args{time}   : 0;
    my $start = time;
    $global_start_time = $start;

    $global_name = $name;

    $pid = fork and return;
    while (1) {
        foreach my $index (1..$size) {
            my $mark = $type ? $mark[$index % 8] : q{=};
            printf "$name...[%s%s%s]", q{ } x $index, $mark, q{ } x ($size - $index + 1);
            printf " (%f sec elapsed)\r", (time - $start) if $time;
            usleep 200000;
        }

        foreach my $index (1..$size) {
            my $mark = $type ? $mark[($index % 8) * -1] : q{=};
            printf "$name...[%s%s%s]", q{ } x ($size - $index + 1), $mark, q{ } x $index;
            printf " (%f sec elapsed)\r" , (time - $start ) if $time;
            usleep 200000;
        }
    }
}

sub pulse_stop {
    kill 9 => $pid;
    my $length = length($global_name);
    printf "$global_name%sDone%s\n", q{.} x (35 - $length), q{ } x 43;
    my $elapsed_time = time - $global_start_time;
    return $elapsed_time;
}

1; # End of Term::Pulse