将嵌入式Pod打印为带有termcap转义符的格式化文本

时间:2019-04-18 12:32:22

标签: perl6 termcap

我正在尝试将嵌入式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

输出

enter image description here

我试图在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

输出

enter image description here

如所见,Perl 6输出中缺少ANSI termcap转义。如何在Perl 6中获得ANSI功能,例如粗体字和带下划线的文本?

2 个答案:

答案 0 :(得分:4)

Pod :: To :: Text接受启用它的环境变量POD_TO_TEXT_ANSI。但是,如果在解析perl 6代码之前加载了所选的DOC模块,则在Pod::To相位器中设置env var可能为时已晚。

答案 1 :(得分:2)

关于您的问题:

  

如何在Perl 6中获得ANSI功能,例如粗体字和带下划线的文本?

您可能想给Terminal::ANSIColor a try,但是您需要自己添加ANSI转义码;在POD上不会自动工作