.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Twiddle 3pm" .TH Twiddle 3pm "2022-11-20" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Term::Twiddle \- Twiddles a thingy while\-u\-wait .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Term::Twiddle; \& my $spinner = new Term::Twiddle; \& \& $spinner\->start; \& system(\*(Aqtar\*(Aq, \*(Aq\-xvf\*(Aq, \*(Aqsome_phat_tarfile.tar\*(Aq); \& $spinner\->stop; \& \& $spinner\->random; ## makes it appear to really struggle at times! \& $spinner\->start; \& &some_long_function(); \& $spinner\->stop; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Always fascinated by the spinner during FreeBSD's loader bootstrap, I wanted to capture it so I could view it any time I wanted to\*(--and I wanted to make other people find that same joy I did. Now, anytime you or your users have to wait for something to finish, instead of twiddling their thumbs, they can watch the computer twiddle its thumbs. .SS "During Twiddling" .IX Subsection "During Twiddling" Once the twiddler/spinner is in motion you need to do something (e.g., unpack a tar file, call some long function, etc.). You can do almost anything in between \fBstart\fR and \fBstop\fR as long as there are no \&\fBsleep\fR calls in there (unless the process has been forked, as in a Perl \fBsystem\fR call). From Time::HiRes: .PP .Vb 3 \& Use of interval timers may interfere with alarm(), sleep(), and \& usleep(). In standard\-speak the "interaction is unspecified", \& which means that anything may happen: it may work, it may not. .Ve .PP Try not to do any terminal I/O while the twiddler is going (unless you don't mind dragging the twiddler around with your cursor). .SS "Spinner Methods" .IX Subsection "Spinner Methods" .IP "\fBnew\fR" 4 .IX Item "new" Creates a new Twiddle object: .Sp .Vb 1 \& my $spinner = new Term::Twiddle; .Ve .Sp Optionally initializes the Twiddle object: .Sp .Vb 2 \& ## a moderately paced spinner \& my $spinner = new Term::Twiddle( { rate => 0.075 } ); .Ve .IP "\fBstart\fR" 4 .IX Item "start" Starts the twiddler twiddling: .Sp .Vb 1 \& $spinner\->start; .Ve .IP "\fBstop\fR" 4 .IX Item "stop" Stops the twiddler: .Sp .Vb 1 \& $spinner\->stop; .Ve .IP "\fBthingy\fR" 4 .IX Item "thingy" Creates a new thingy. The argument is a reference to a list of strings to print (usually single characters) so that animation looks good. The default spinner sequence looks like this: .Sp .Vb 1 \& $spinner\->thingy( [ "\e\e", "|", "/", "\-" ] ); .Ve .Sp an arrow could be done like this: \f(CW$spinner\fR\->thingy( [ \*(L"\-\-\-\->\*(R", \*(L" \-\-\-\-\->\*(R", \*(L" \-\-\-\-\->\*(R", \*(L" \-\-\-\-\->\*(R", \*(L" \-\-\-\-\->|\*(R", \*(L" \-\-\-\->|\*(R", \*(L" \-\-\->|\*(R", \*(L" \-\->|\*(R", \*(L" \->|\*(R", \*(L" >|\*(R", \*(L" |\*(R", \*(L" \*(R"]); .Sp Look at the test.pl file for this package for more fun thingy ideas. .IP "\fBrate\fR" 4 .IX Item "rate" Changes the rate at which the thingy is changing (e.g., spinner is spinning). This is the time to wait between thingy characters (or \&\*(L"frames\*(R") in seconds. Fractions of seconds are supported. The default rate is 0.175 seconds. .Sp .Vb 1 \& $spinner\->rate(0.075); ## faster! .Ve .IP "\fBprobability\fR" 4 .IX Item "probability" Determines how likely it is for each step in the thingy's motion to change rate of change. That is, each time the thingy advances in its sequence, a random number from 1 to 100 is generated. If \&\fBprobability\fR is set, it is compared to the random number. If the probability is greater than or equal to the randomly generated number, then a new rate of change is randomly computed (between 0 and 0.2 seconds). .Sp In short, if you want the thingy to change rates often, set \&\fBprobability\fR high. Otherwise set it low. If you don't want the rate to change ever, set it to 0 (zero). 0 is the default. .Sp .Vb 5 \& ## half of all sequence changes will result in a new rate of change \& $spinner\->probability(50); \& $spinner\->start; \& do_something; \& $spinner\->stop; .Ve .Sp The purpose of this is to create a random rate of change for the thingy, giving the impression that whatever the user is waiting for is certainly doing a lot of work (e.g., as the rate slows, the computer is working harder, as the rate increases, the computer is working very fast. Either way your computer looks good!). .IP "\fBrandom\fR" 4 .IX Item "random" Invokes the \fBprobability\fR method with the argument specified. If no argument is specified, 25 is the default value. This is meant as a short-cut for the \fBprobability\fR method. .Sp .Vb 1 \& $spinner\->random; .Ve .IP "\fBstream\fR" 4 .IX Item "stream" Select an alternate stream to print on. By default, \s-1STDOUT\s0 is printed to. .Sp .Vb 1 \& $spinner\->stream(*STDERR); .Ve .SS "Alternative Spinner Methods" .IX Subsection "Alternative Spinner Methods" Since version 2.70, \fBTerm::Twiddle\fR objects support a couple of new spinners that aren't so \*(L"plain\*(R". 2.70 includes a \fBbounce\fRing ball and a \fBswish\fRing object (that's the best name I could think to call it). .PP The following methods are used to activate and customize these new spinners. .IP "\fBtype\fR" 4 .IX Item "type" Use this method to set the type of spinner. The default type (no type) is whatever \fBthingy\fR is set to. Two other currently supported types are \fBbounce\fR, and \fBswish\fR. These may be set in the constructor: .Sp .Vb 2 \& my $sp = new Term::Twiddle({ type => \*(Aqbounce\*(Aq }); \& $sp\->start; .Ve .Sp or you can set it with this \fBtype\fR method: .Sp .Vb 2 \& my $sp = new Term::Twiddle; \& $sp\->type(\*(Aqbounce\*(Aq); .Ve .Sp There is currently no way to add new \fBtype\fRs without some hacking (it's on the \*(L"to do\*(R" list). .IP "\fBwidth\fR" 4 .IX Item "width" This method is only used when \fBtype\fR is undefined (i.e., a normal spinner). \fBwidth\fR determines how wide the \fBbounce\fR or \fBswish\fR objects go. \fBwidth\fR may be set in the constructor: .Sp .Vb 2 \& my $sp = new Term::Twiddle({ type => \*(Aqbounce\*(Aq, width => 60 }); \& $sp\->start; .Ve .Sp or you can set it with this \fBwidth\fR method: .Sp .Vb 2 \& my $sp = new Term::Twiddle({ type => \*(Aqswish\*(Aq }); \& $sp\->width(74); .Ve .IP "\fBdelay\fR" 4 .IX Item "delay" Determines the speed of motion of the object. Usually the default is fine (and each object has its own default delay option for optimal aesthetics). .SH "EXAMPLES" .IX Header "EXAMPLES" Show the user something while we unpack the archive: .PP .Vb 5 \& my $sp = new Term::Twiddle; \& $sp\->random; \& $sp\->start; \& system(\*(Aqtar\*(Aq, \*(Aq\-zxf\*(Aq, \*(Aq/some/tarfile.tar.gz\*(Aq); \& $sp\->stop; .Ve .PP Show the user a bouncing ball while we modify their configuration file: .PP .Vb 2 \& my $sp = new Term::Twiddle( { type => \*(Aqbounce\*(Aq } ); \& $sp\->start; \& \& ## there must not be any \*(Aqsleep\*(Aq calls in this! \& do_config_stuff(); \& \& $sp\->stop; .Ve .SH "AUTHOR" .IX Header "AUTHOR" Scott Wiersdorf, .SH "CAVEATS" .IX Header "CAVEATS" .IP "\(bu" 4 Prolly won't run on platforms lacking \fBsetitimer\fR. Will run on Cygwin/Win32 (reported by Zak Zebrowski\*(--thanks!). .IP "\(bu" 4 .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" .IP "\(bu" 4 Thanks to Tom Christiansen for the timer code (found lurking in an old \&\s-1FAQ\s0 somewhere). He probably never had an idea that it would be part of one of the most useful modules on \s-1CPAN\s0 ;o) .Sp The timer code has since been replaced by \fBTime::HiRes\fR's \&\fBsetitimer\fR function, but it is good to thank Mr. Christiansen for his goodness to Perl anyway. .IP "\(bu" 4 \&\*(L"Drew\*(R" (drew@drewtaylor.com) from rt.cpan.org for suggesting the removal of 'use warnings' for the faithful 5.005 users. .IP "\(bu" 4 Orignal swishing motion filched from \fBTerm::ReadKey\fR's test.pl by Kenneth Albanowski (kjahds@kjahds.com). Danke! .SH "SEE ALSO" .IX Header "SEE ALSO" perl.