text
stringlengths
0
834k
my $n;
for my $k (@fields[0 .. $#fields-1]) {
my $max = $max_width{$k};
my $sz = $width{$k};
$biggest = $k, $n = $max - $sz if $max - $sz < $n;
}
$width{$right}++;
$width{$biggest}--;
}
my $picture;
$picture = ""\%${index_sz}s ""; # printf picture
$picture .= join ' ', map {
my $w = $width{$_};
my $c = $just{$_};
my $pad = $c eq '>' ? '' : '-';
""\%${pad}${w}s"" # printf picture
} @fields;
($picture, \@fields, [@width{@fields}]);
}
sub print_formatted {
my $o = shift;
my $targ = $o->conf('target');
my @items = map { $_->getppd_obj($targ)->result } @{shift(@_)};
my $selected = shift;
my $format;
# Generate a picture and a list of fields for Text::Autoformat:
my (@fields, %width);
my ($picture, $f, $w) = $o->picture_optimized(\@items);
$picture .= ""\n"";
@fields = @$f;
@width{@fields} = @$w;
# The line-breaking sub: use '~' as hyphenation signal
my $wrap = sub {
my ($str, $maxlen, $width) = @_;
my $field = substr($str, 0, $maxlen - 1) . '~';
my $left = substr($str, $maxlen - 1);
($field, $left);
};
my $lines = 0;
my $i = 1;
my @text;
my %seen;
for my $pkg (@items) {
my $star = (defined $selected and $selected == $i - 1) ? ""*"" : "" "";
my $num = ""$star $i."";
my @vals = (
map {
my $field = $_;
my $method = $meth{$field};
local $_ = $pkg->$method;
my $val = defined $filt{$field} ? eval $filt{$field} : $_;
($val) = $wrap->($val, $width{$field})
if length $val > $width{$field};
$val;
}
@fields
);
# my $key = join '', @vals;
# if (exists $seen{$key}) {
# my $index = $seen{$key};
# substr($text[$index], 0, 1) = '+';
# next;
# }
# $seen{$key} = $i - 1;
(my $inc = sprintf $picture, $num, @vals) =~ s/[ ]+$//;
push @text, $inc;
$i++;
}
# And, page it.
$o->page(join '', @text);
}
}
sub tree_pkg {
my $o = shift;
my @rlist = $o->reps_on;
my $tar = $o->conf('target');
my $pkg = shift;
my $ppd;
if (eval { $pkg->isa('PPM::Package') }) {
$ppd = $pkg->getppd_obj($tar);
unless ($ppd->ok) {
$o->warn($ppd->msg);
return;
}
$ppd = $ppd->result;
}
else {
my ($s, $i) = $o->cache_find('search', $pkg);
if ($i >= 0) {
$ppd = $o->cache_entry('search', $i, $s);
}
else {
my $ok = PPM::UI::describe(\@rlist, $tar, $pkg);
unless ($ok->is_success) {