Spinning rod animation/Text: Difference between revisions
→{{header|Perl 6}}: Add a scrolling "marquee" option and a demo
(Add Python) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add a scrolling "marquee" option and a demo) |
||
Line 113:
=={{header|Perl 6}}==
{{works with|Rakudo|2018.05}}
Traditionally
This implementation will accept an array of elements to use as its throbber frames, or as a scrolling marquee and optionally a delay before it returns the next element.
<lang perl6>class throbber {
has @.
has $.delay is rw = 0;
has $!index = 0;
has Bool $.marquee = False;
method next {
$!index = ($!index + 1) % +@.
sleep $.delay if $.delay;
("\b" x @.frames) ~ @.frames.rotate($!index).join;
}
else {
"\b" ~ @.frames[$!index];
}
}
}
my $rod = throbber.new( :
print "\e[?25lLong running process... ";
print $rod.next for ^20;
▲my $clock = throbber.new( :members("🕐" .. "🕛") );
print "\b \nSomething else with a delay... ";
until my $done {
# do something in a loop;
sleep 1/12;
print $clock.next;
$done = True if $++ >= 60;
}
my $scroll = throbber.new( :frames('PLEASE STAND BY... '.comb), :delay(.1), :marquee );
END { print "\b \e[?25h\n" } # clean up on exit</lang>▼
print "\b \nEXPERIENCING TECHNICAL DIFFICULTIES: { $scroll.frames.join }";
print $scroll.next for ^95;
=={{header|Python}}==
|