Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created Aug 4, 2022
Embed
What would you like to do?
use v6.d;
# my @loop = |("\x1F550" .. "\x1F55B") xx *;
# react whenever Supply.interval(0.1) {
# state $it = @loop.iterator;
# print "\b\b" ~ $it.pull-one;
# }
sub progress-bar($max, $width = 10) {
sub ($current) {
return if $current > $max;
my $progress = round(try { $current / $max * ($width - 2) } // 0);
print "\b" x $width ~ '[' ~ ('#' x $progress) ~ (' ' x (($width - 2) - $progress)) ~ ']';
}
}
my &bar = progress-bar(3000, 25);
react whenever Supply.interval(0.01) {
bar($++);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment