Commits

Shlomi Fish committed 1baac6b

Add the countdown scripts to generate a countdown.

This is like sleep except that it displays the number of remaining seconds.

Comments (0)

Files changed (2)

shlomif-settings/home-bin-executables/bin/countdown.p6

+use v6;
+
+sub MAIN($delay)
+{
+    my $start = now;
+    my $end = $start + $delay;
+
+    my $last_printed;
+    while (my $t = now) < $end
+    {
+        my $new_to_print = ($end - $t).floor;
+        # say $new_to_print;
+        if !defined($last_printed) or $new_to_print != $last_printed
+        {
+            $last_printed = $new_to_print;
+            print "Remaining {$new_to_print.fmt('%i')}/{$delay}{' ' x 40}\r";
+            $*OUT.flush;
+        }
+        sleep(0.3);
+    }
+}

shlomif-settings/home-bin-executables/bin/countdown.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Time::HiRes qw(sleep time);
+use POSIX qw();
+use IO::Handle;
+
+my $delay = shift(@ARGV);
+
+STDOUT->autoflush(1);
+{
+    my $start = time();
+    my $end = $start + $delay;
+
+    my $last_printed;
+    while ((my $t = time()) < $end)
+    {
+        my $new_to_print = POSIX::floor($end - $t);
+        # print "$new_to_print\n";
+        if (!defined($last_printed) or $new_to_print != $last_printed)
+        {
+            $last_printed = $new_to_print;
+            print "Remaining $new_to_print/$delay", ' ' x 40, "\r";
+        }
+        sleep(0.1);
+    }
+}