package YAPI; { use strict; use warnings; use Object::InsideOut; my @count :Field; my @prog :Field; my %init_args :InitArgs = ( 'prog' => { 'Field' => \@prog, 'Default' => [ qw(/ - \ |) ], # Twirling bar 'Type' => 'List' } ); sub start { my ($self, $msg) = @_; $| = 1; # Autoflush print("$msg \e[?25l"); # Print 'msg' and hide cursor $self->progress(); } sub progress { my $self = shift; print("\b", $prog[$$self][$count[$$self]++ % @{$prog[$$self]}]); } sub done { my $self = shift; my $msg = shift || ' '; print("\b$msg\e[?25h\n"); # Print 'msg' and restore cursor } } 1; #### #!/usr/bin/perl use strict; use warnings; use YAPI; MAIN: { my $prog = YAPI->new('prog' => [ qw(^ > v <) ]); # My own invention $prog->start('Working: '); foreach (1..10) { sleep(1); $prog->progress(); } $prog->done('done'); } exit(0); # EOF