I want to show an animation that alternate the character /
, |
and \
.
How am I supposed to write always in the same cell of the terminal? I need to bring the cursor back of one position.
Most terminals will handle a backspace (chr(8)
) by moving the cursor back. The key is to disable buffering.
use Time::HiRes qw( sleep );
$| = 1; # Disable buffering on STDOUT.
my $BACKSPACE = chr(0x08);
my @seq = qw( | / - \ );
for (;;) {
print $seq[0];
push @seq, shift @seq;
sleep 0.200;
print $BACKSPACE;
}
print "$BACKSPACE $BACKSPACE";
An variant of ikegami's answer :)
use Time::HiRes qw(sleep);
$| = 1; # Disable buffering on STDOUT ;)
for(1..10) {
for (qw( | / - \ )) {
print "$_\b";
sleep 0.2;
}
}
print
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With