Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print embedded Pod as formatted text with termcap escapes

Tags:

raku

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

Output:

enter image description here

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:

enter image description here

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?

like image 812
Håkon Hægland Avatar asked Apr 18 '19 12:04

Håkon Hægland


2 Answers

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.

like image 199
timotimo Avatar answered Oct 29 '22 19:10

timotimo


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

like image 2
jjmerelo Avatar answered Oct 29 '22 20:10

jjmerelo