When doing some tests for "Emoji can be hard to see on the command line", I typed in an incorrect character for a Unicode® code point and was presented with a clock face. That reminded me of something I've been meaning to do for quite some time, so here it is.

The basic idea is to have a progress spinner that is a little more visually appealing than the usual text versions which cycle through "| / - \".

There are two versions: one with clock faces and one with phases of the moon. I've provided all of the code points, so that's one job anyone wanting to use this doesn't need to do. The code points for the clock faces are not sequential, so I've provided the order from 12:00 to 11:30; again, another fiddly job taken care of. The logic is simple and probably well-known to many; but, if not, that's done as well.

I've specified 'use 5.018;'. All of the characters were introduced in Unicode® v6.0 (determined via Unicode::UCD::charprops_all()). You may actually get away with 'use 5.014;'. I chose 5.18 based on the deltas (my emphasis throughout):

The following script is barebones and is really only intended as an example demo. Anyone wishing to use this will likely want additional output text — e.g. percentages, "done X of Y", and the like — so I saw no point in trying to guess such requirements.

#!/usr/bin/env perl use 5.018; use warnings; use open qw{:std :encoding(UTF-8)}; use Time::HiRes 'usleep'; { my @code_points = qw{ 1f55b 1f567 1f550 1f55c 1f551 1f55d 1f552 1f55e 1f553 1f55f 1f554 1f560 1f555 1f561 1f556 1f562 1f557 1f563 1f558 1f564 1f559 1f565 1f55a 1f566 }; my @chars = map chr hex, @code_points; my $total = @chars; my $index = $total; for (1 .. 50) { local $| = 1; $index %= $total; print "\b\b", $chars[$index++]; usleep 250_000; } print "\n"; } { my @code_points = qw{ 1f311 1f312 1f313 1f314 1f315 1f316 1f317 1f318 }; my @chars = map chr hex, @code_points; my $total = @chars; my $index = $total; for (1 .. 25) { local $| = 1; $index %= $total; print "\b\b", $chars[$index++]; usleep 500_000; } print "\n"; }

— Ken


In reply to Emoji Progress Spinners by kcott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.