我正在尝试将嵌入式 Pod 作为 ANSI 文本输出到终端。在 Perl 5 中,我可以使用Pod::Text::Termcap
:
use strict;
use warnings;
use Pod::Text::Termcap;
my $str = do {local $/; <DATA>};
my $parser = Pod::Text::Termcap->new();
$parser->parse_string_document( $str, \*STDERR );
__DATA__
=head1 SYNOPSIS
my_test_command I<filename> [OPTIONS]
=head1 ARGUMENTS
=over 4
=item I<filename>
File name to test
=back
=head1 OPTIONS
=over 4
=item B<--help>
Prints help
=back
=head1 DESCRIPTION
A sample test command with embedded Pod
输出:
我试图在 Perl 6 中达到同样的效果:
use v6;
%*ENV<POD_TO_TEXT_ANSI> = 1;
my @lines;
for $=pod -> $pod-block {
for $pod-block.contents -> $pod-item {
use Pod::To::Text;
push @lines, pod2text($pod-item);
}
}
say @lines.join("\n\n");
=begin pod
=head1 SYNOPSIS
my_test_command I<filename> [OPTIONS]
=head1 ARGUMENTS
=item I<filename>
File name to test
=head1 OPTIONS
=item B<--help>
Prints help
=head1 DESCRIPTION
A sample test command with embedded Pod
=end pod
输出:
正如所见,Perl 6 输出中缺少 ANSI termcap 转义。如何在 Perl 6 中获得 ANSI 功能,如粗体和带下划线的文本?