in reply to Creating a Sparkle in perl
Put this part in a file called YAPI.pm somewhere in @INC:
And here's a sample on how to use it: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 curs +or } } 1;
Enjoy, and Happy New Year!#!/usr/bin/perl use strict; use warnings; use YAPI; MAIN: { my $prog = YAPI->new('prog' => [ qw(^ > v <) ]); # My own invent +ion $prog->start('Working: '); foreach (1..10) { sleep(1); $prog->progress(); } $prog->done('done'); } exit(0); # EOF
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating a Sparkle in perl
by jdhedden (Deacon) on Sep 07, 2007 at 20:00 UTC |