From: Andrew Ruthven <andrew@etc.gen.nz>
Date: Thu, 29 Nov 2007 18:02:39 +0000 (+1300)
Subject: Put all the one liners together in the output and make them line up nicely.
X-Git-Tag: 0.6.0~26
X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc02f52c48e466ee9650bd19d701b37c8b4c3741;p=mythtv-status.git

Put all the one liners together in the output and make them line up nicely.
---

diff --git a/ChangeLog b/ChangeLog
index e03f14c..676abed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,8 @@
 	Be a bit more forgiving on the XML we're receiving.
 	Show how much disk space is used - currently only total.
 	Rename "Time till next recording" to "Next Recording In".
+	Put all the one liners together in the output and make them line
+	  up nicely.
 
 2007-11-23	Andrew Ruthven
 	Don't set the background when changing the colour.
diff --git a/bin/mythtv-status b/bin/mythtv-status
index aa5665e..9f4a1a7 100755
--- a/bin/mythtv-status
+++ b/bin/mythtv-status
@@ -42,6 +42,7 @@ GetOptions(
   'v|version'    => \&print_version,
   'email=s@'     => \@email,
   'email-only-on-conflict' => \$email_only_on_conflict,
+
   'status!'               => \$display{'Status'},
   'encoders!'             => \$display{'Encoders'},
   'recording-now!'        => \$display{'Recording Now'},
@@ -109,6 +110,14 @@ my $next_time = undef;
 
 # The blocks of output which we might generate.
 my @blocks = (
+  # All the one liners together
+  {
+    'name' => 'One Liners',
+    'type' => 'sub',
+    'template' => '',
+    'sub' => sub { return 'Place holder' },
+  },
+
   # Date/Time from server
   {
     'name'  => 'Status',
@@ -305,11 +314,36 @@ for my $block (@blocks) {
   }
 
   if (defined $result && $result ne '' && ! defined $hide) {
-    $output .= "$block->{'name'}:" . ($block->{'format'} eq 'one line' ? ' ' : "\n");
-    $output .= $result . "\n\n";
+    if ($block->{'format'} eq 'one line') {
+      push @oneliners, [ $block->{'name'}, $result ];
+    } else {
+      $output .= "$block->{'name'}:\n";
+      $output .= $result . "\n\n";
+    }
   }
 }
 
+# Deal with the one liners.
+if (scalar(@oneliners) > 0) {
+  # Find the longest header
+  my $length = 0;
+  for $line (@oneliners) {
+     if (length($line->[0]) > $length) {
+       $length = length($line->[0]);
+     }
+  }
+
+  # Put the one liners together, with leading dots to the colon.
+  my $oneliners = "";
+  for $line (@oneliners) {
+     $oneliners .= "$line->[0]"
+       . ('.' x ($length - length($line->[0]))) . ": $line->[1]\n";
+  }
+
+  # What a hacky way of putting the one liners where I want them...
+  $output =~ s/^One Liners:\nPlace holder\n/$oneliners/m;
+}
+
 # Either print the status out, or email it.
 if (scalar(@email) == 0) {
   print "\n$output";