将嵌入式Pod打印为带termcap转义符的格式化文本 [英] Print embedded Pod as formatted text with termcap escapes

查看:107
本文介绍了将嵌入式Pod打印为带termcap转义符的格式化文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将嵌入式Pod作为ANSI文本输出到终端.在Perl 5中,我可以使用 Pod::Text::Termcap :

I am trying to output embedded Pod as ANSI text to the terminal. In Perl 5 I can use 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中实现相同的目标:

I tried to achieve the same in 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功能,例如粗体字和带下划线的文本?

As seen the ANSI termcap escapes are missing in the Perl 6 output. How can I get ANSI features like bold face and underlined text in Perl 6?

推荐答案

Pod :: To :: Text接受将其打开的环境变量POD_TO_TEXT_ANSI.但是,如果在解析perl 6代码之前加载了选定的Pod::To模块,则在DOC移相器内部设置env var可能为时已晚.

Pod::To::Text accepts an environment variable POD_TO_TEXT_ANSI that turns this on. Setting that env var inside of a DOC phaser might be too late, though, if the selected Pod::To module is loaded before the perl 6 code is parsed however.

这篇关于将嵌入式Pod打印为带termcap转义符的格式化文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆