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.


In reply to Re: Term::Twiddle on Win32 or how to use spinner by BrowserUk
in thread Term::Twiddle on Win32 or how to use spinner by icius

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.