summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2010-11-09 21:41:08 +0100
committerDaniel Friesel <derf@finalrewind.org>2010-11-09 21:41:08 +0100
commit8e6c10856c9a960025f46d6d7d29b41569f5c171 (patch)
tree67c79229c5f670b918f5a1876b80a129dbffa3f4
parentbcc8ada7314bc7c38b32e41eba0472ba9429d7ec (diff)
vzds: Merge with zds (adds console output)
-rwxr-xr-xbin/vzds36
1 files changed, 32 insertions, 4 deletions
diff --git a/bin/vzds b/bin/vzds
index 363f5c1..e494e08 100755
--- a/bin/vzds
+++ b/bin/vzds
@@ -6,8 +6,14 @@ use autodie;
use Date::Format;
use GD;
+use Getopt::Std;
use POSIX 'ceil';
use Simplestore;
+use Term::ANSIColor;
+
+my %opts;
+
+getopts('cg', \%opts);
my $count = shift // 5;
@@ -28,6 +34,10 @@ my $green = $im->colorAllocate(200, 255, 200);
my $yellow = $im->colorAllocate(255, 255, 200);
my $red = $im->colorAllocate(255, 191, 191);
+my $text;
+
+getopts('cg', \%opts);
+
for my $i (1 .. $count) {
my @time = localtime(time + (3600 * 24 * $i));
@@ -49,6 +59,7 @@ for my $i (1 .. $count) {
$im->string(gdSmallFont, $x_off + 2, $y_off + 2, "${day} ${mday}",
$black);
$im->rectangle($x_off, $y_off, $x_off + 40, $y_off + 40, $gray);
+ $text .= strftime("%a %b %d\n", @time);
next;
}
@@ -58,15 +69,19 @@ for my $i (1 .. $count) {
if ($cur < 8) {
$colour = $blue;
+ $text .= color('white on_blue');
}
elsif ($cur < 10) {
$colour = $green;
+ $text .= color('black on_green');
}
elsif ($cur < 13) {
$colour = $yellow;
+ $text .= color('black on_yellow');
}
else {
$colour = $red;
+ $text .= color('white on_red');
}
$im->filledRectangle($x_off + 1, $y_off + 1, $x_off + 39, $y_off + 39,
@@ -77,11 +92,24 @@ for my $i (1 .. $count) {
$cur), $black);
$im->rectangle($x_off, $y_off, $x_off + 40, $y_off + 40, $gray);
+ $text .= sprintf(
+ "%s%s %02d:00 -> %02d:00\n",
+ strftime("%a %b %d", @time),
+ color('reset'),
+ $cur,
+ $cur + 8,
+ );
+
}
$im->rectangle(0, 0, $w - 1, $h -1, $gray);
-open(my $out_fh, '>', '/tmp/vzds.png');
-binmode $out_fh;
-print $out_fh $im->png();
-close($out_fh);
+if ($opts{'c'}) {
+ print $text;
+}
+if ($opts{'g'}) {
+ open(my $out_fh, '>', '/tmp/vzds.png');
+ binmode $out_fh;
+ print $out_fh $im->png();
+ close($out_fh);
+}