From bc02f52c48e466ee9650bd19d701b37c8b4c3741 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Fri, 30 Nov 2007 07:02:39 +1300 Subject: [PATCH] Put all the one liners together in the output and make them line up nicely. --- ChangeLog | 2 ++ bin/mythtv-status | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) 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"; -- 2.30.2