diff options
Diffstat (limited to 'sbocheck')
-rwxr-xr-x | sbocheck | 40 |
1 files changed, 29 insertions, 11 deletions
@@ -14,7 +14,6 @@ use strict; use warnings FATAL => 'all'; use SBO::Lib; use Getopt::Long; -use Text::Tabulate; use File::Basename; my $self = basename($0); @@ -45,30 +44,49 @@ update_tree; sub get_update_list() { print "Checking for updated SlackBuilds...\n"; my $updates = get_available_updates; - # pretty formatting. + # consistent formatting - determine longest version string, which will tell + # us the max minimum length of the left side of the output for stuff that + # fits in 80 chars; stuff that doesn't will overflow. + my @up_lengths; + push @up_lengths, length $$updates[$_]{update} for keys @$updates; + my @s_up_lengths = sort {$b <=> $a} @up_lengths; + my $up_length = $s_up_lengths[0]; + # "needs updating" bit without version is 30 characters + my $remaining = 80 - ($up_length + 30); + my @lengths; + push @lengths, length "$$updates[$_]{name}-$$updates[$_]{installed}" + for keys @$updates; + my @s_lengths = sort {$b <=> $a} @lengths; + my $min; + FIRST: for my $len (@s_lengths) { + if ($len < $remaining) { + $min = $len; + last FIRST; + } + } + $min = $remaining unless $min; + my @listing; for my $update (@$updates) { - my $string = "$$update{name}-$$update{installed}"; - $string .= " < needs updating (SBo has $$update{update})\n"; - push @listing, $string; + push(@listing, sprintf "%-${min}s < needs updating (SBo has %s)", + "$$update{name}-$$update{installed}", "$$update{update}"); } return \@listing; } -# Text::Tabulate and print list of updates +# print list of updates sub print_output($) { exists $_[0] or script_error 'print_output requires an argument'; my $listing = shift; if (exists $$listing[0]) { - my $tab = new Text::Tabulate(); - $tab->configure(tab => '\s'); - my $output = $tab->format(@$listing); - say "\n". $output; + print "\n"; + say $_ for @$listing; + print "\n"; # save a log of available updates my $logfile = '/var/log/sbocheck.log'; unlink $logfile if -f $logfile; my $log_fh = open_fh($logfile, '>'); - print {$log_fh} $output; + say {$log_fh} $_ for @$listing; close $log_fh; say "A copy of the above result is kept in $logfile\n"; } else { |