http://www.perlmonks.org?node_id=235416

icius has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks! I have been perusing the prolific "spinner" posts and there are a number of options out there. I am trying to get a spinner/status bar to work like the Term::Twiddle module, i.e.

$spinner->start;

do some other Perl stuff of my choosing

$spinner->stop;

The spinners all look great but they are all infinite loops or counted loops. I need to be able to start and stop like above. The best solution would be if someone knows of a version of Term::Twiddle that works on Windows. The next best would be if someone knows how to use any of the spinners in the above fashion. Thanks!!

Replies are listed 'Best First'.
Re: Term::Twiddle on Win32 or how to use spinner
by BrowserUk (Patriarch) on Feb 15, 2003 at 06:14 UTC

    Here's a roll-your-own asynchronous spinner using fork under Win32. It's pretty crude as-is, but could be fairly easily wrapped up in a nicer interface.

    Update: Added a 100ms sleep (select) to stop the spinner using half the CPU.

    #! perl -sw use strict; use Win32::Mutex; $|++; my $name = 'Spin_control'; if ( my $pid = fork() ) { my $n=0; my $mutex =Win32::Mutex->new(0,$name) or die $^E; while($mutex->wait() != -1) { $mutex->release(); print chr(13) . 'Busy'; print substr( '-\|/', $n++ % 4,1) . chr(8); select(undef,undef,undef,0.1); ## Added. } } elsif ( $pid == 0 ) { my $mutex = Win32::Mutex->open($name); $mutex->wait(); print 'Not busy' . chr(13) for 1..1000; print $/; $mutex->release(); my $count; $count++ for 1..1_000_000; $mutex->wait(); print 'Counted to ', $count; } else { warn 'fork() failed'; }

    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Re: Term::Twiddle on Win32 or how to use spinner
by tretin (Friar) on Feb 15, 2003 at 05:47 UTC
    I'd check this thread for your spinner needs. If anybody has term::twiddle on windows, CPAN could use it.

    sorry I can't be of more use, but hopefully you can find what you need there