App-Greple-charcode
view release on metacpan or search on metacpan
lib/App/Greple/annotate.pm view on Meta::CPAN
} elsif ($current->total > 0 and $current->last->end == $start) {
$head = 'â';
$start = $current->last->start;
substr($indent, $start) = '';
} elsif ($start > 0) {
$start = vwidth($progress =~ s/\X\z//r);
substr($indent, $start) = '';
}
}
my $marker = sub {
my($head, $match) = @_;
sprintf("%s%s%s\N{NBSP}%s",
$indent, $head, 'â',
$ANNOTATE->(column => $start, match => $match));
};
$current->push( do {
if ($config->{split}) {
map {
my $out = $marker->($head, $_);
$head = 'â';
Local::Annon->new($start, $end, $out);
} $slice =~ /./sg;
} else {
Local::Annon->new($start, $end, $marker->($head, $slice));
}
} );
}
$indent .= sprintf("%-*s", $end - $start, $indent_mark);
$progress .= $slice;
$start = $end;
}
@{$current->count} == 0 and next;
my $alignto = $config->{alignto};
if ($alignto > 0 and $current->total > 0) {
alignto($current, $alignto > 1 ? $alignto : $current->last->[0]);
}
$annotation->join($current);
}
if ($config->{alignto} == -1) {
alignto($annotation, $annotation->maxpos);
}
elsif ($config->{alignto} == -2) {
if (my $maxlen = max map { vwidth($grep->cut($_->[0]->@*)) } @result) {
alignto($annotation, $maxlen - 1);
}
}
}
sub alignto {
my($list, $pos) = @_;
for (@{$list->annotation}) {
if ((my $extend = $pos - $_->[0]) > 0) {
$_->annon =~ s/(?=([â]))/$1 x $extend/e;
}
}
}
sub annotate {
config('annotate') or return;
if (my @annon = $annotation->shift) {
say $_->annon for @annon;
}
undef;
}
1;
__DATA__
builtin annotate! $opt_annotate
option default \
--postgrep '&__PACKAGE__::prepare' \
--callback '&__PACKAGE__::annotate'
option --annotate::config \
--prologue &__PACKAGE__::config($<shift>)
option --config --annotate::config
option --split --annotate::config split=1
option --alignto --annotate::config alignto=$<shift>
option --align --annotate::config alignto=1
option --no-align --annotate::config alignto=0
option --align-all --annotate::config alignto=-1
option --align-side --annotate::config alignto=-2
( run in 1.775 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )