aboutsummaryrefslogtreecommitdiff
path: root/sbocheck
diff options
context:
space:
mode:
authorJ Pipkin <j@dawnrazor.net>2013-01-03 03:00:09 -0600
committerJ Pipkin <j@dawnrazor.net>2013-01-03 03:00:09 -0600
commit31895d53a63c8e93e099a56fe67ccd0cac270590 (patch)
tree18e82fb3bbf9f087fe6e3f684b5400a3de3b0ac5 /sbocheck
parentfa2ffaf281e5b8212a4b0dd96519c0dd35166fc1 (diff)
downloadsbotools-31895d53a63c8e93e099a56fe67ccd0cac270590.tar.xz
dynamically determine longest minimum within 80
Diffstat (limited to 'sbocheck')
-rwxr-xr-xsbocheck20
1 files changed, 17 insertions, 3 deletions
diff --git a/sbocheck b/sbocheck
index da3a3b8..5b36f57 100755
--- a/sbocheck
+++ b/sbocheck
@@ -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) {