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
Output:
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
Output:
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 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.
Regarding your question:
How can I get ANSI features like bold face and underlined text in Perl 6?
You might want to give Terminal::ANSIColor
a try but you will need to add the ANSI escape codes yourself; it's not going to work automatically on PODs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With