Skip to content

Instantly share code, notes, and snippets.

@Low-power
Created January 30, 2025 04:09
Show Gist options
  • Save Low-power/b2dc5d73ee66a5137e70f721e58f3f1d to your computer and use it in GitHub Desktop.
Save Low-power/b2dc5d73ee66a5137e70f721e58f3f1d to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# Copyright 2015-2025 Rivoreo
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
use strict;
use warnings;
use Time::HiRes qw(gettimeofday usleep);
$SIG{INT} = sub {
print "\e[0m\n";
exit;
};
$| = 1;
my $color_status = 0;
while(1) {
my $color_code;
if($color_status) {
$color_code = "\e[1;30;47m";
$color_status = 0;
} else {
$color_code = "\e[0m";
$color_status = 1;
}
my ($sec, $usec) = gettimeofday;
my @dt = localtime($sec);
printf STDOUT "\r%s%5d-%02d-%02d %02d:%02d:%02d", $color_code,
1900 + $dt[5], 1 + $dt[4], $dt[3], $dt[2], $dt[1], $dt[0];
usleep 1000000 - $usec;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment