Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created August 4, 2022 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfldex/4c1ef3ad5c27aa3a1f176fcbdd1f22cb to your computer and use it in GitHub Desktop.
Save gfldex/4c1ef3ad5c27aa3a1f176fcbdd1f22cb to your computer and use it in GitHub Desktop.
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