diff options
author | J Pipkin <j@dawnrazor.net> | 2013-01-03 03:00:09 -0600 |
---|---|---|
committer | J Pipkin <j@dawnrazor.net> | 2013-01-03 03:00:09 -0600 |
commit | 31895d53a63c8e93e099a56fe67ccd0cac270590 (patch) | |
tree | 18e82fb3bbf9f087fe6e3f684b5400a3de3b0ac5 /sbocheck | |
parent | fa2ffaf281e5b8212a4b0dd96519c0dd35166fc1 (diff) | |
download | sbotools-31895d53a63c8e93e099a56fe67ccd0cac270590.tar.xz |
dynamically determine longest minimum within 80
Diffstat (limited to 'sbocheck')
-rwxr-xr-x | sbocheck | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -44,13 +44,27 @@ update_tree; sub get_update_list() { print "Checking for updated SlackBuilds...\n"; my $updates = get_available_updates; - # consistent formatting - first we need the minimum length for name-version + # 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 = $s_lengths[0]; - $min = 37 if $min > 37; + 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) { |