NAME

Pod::Text::Fancy - Format POD for the terminal, with Japanese line breaking and decoration

SYNOPSIS

perldoc -o fancy Some::Module

PERLDOC="-o fancy" perldoc Some::Module
PERLDOC="-o fancy -w theme:none" perldoc Some::Module
PERLDOC="-o fancy -w theme:dark" perldoc Some::Module
perldoc -o fancy -w base:RebeccaPurple Some::Module
perldoc -o fancy -w base:RebeccaPurple -w wall Some::Module
perldoc -o fancy -w theme:dark -w base:RebeccaPurple Some::Module
perldoc -o fancy -w 'colormap:head1=${base}DU' Some::Module

use Pod::Text::Fancy;
my $parser = Pod::Text::Fancy->new(width => 80, theme => 'dark');
$parser->parse_from_file('file.pod');

DESCRIPTION

Pod::Text::Fancy is a subclass of Pod::Text for reading POD written in Japanese and other languages with wide characters.

It differs from Pod::Text in the following.

Folding by display width

Text is folded by Text::ANSI::Fold, which counts the display width of wide characters (Japanese, Chinese, Korean) as two columns. Japanese text is broken according to its line breaking rules: prohibited characters such as 。 and 」 are not placed at the start of a line, but hung at the end of the previous line. A hung line may exceed the given width by up to 4 columns. The width is the desired length of a line, and the hung characters stick out of it like a period written in the margin of manuscript paper.

Line breaks between wide characters

Line breaks in the source between two wide characters, and after wide punctuation such as 。, are removed, instead of being turned into a space. Other line breaks next to Hangul are turned into a space, because Korean words are separated by spaces.

Width of item tags

The tag of =item is measured by display width.

Decoration

The output is decorated by a theme. The default theme quiet uses no color: =head1, =head2 and B<> text are bold, =head3, =head4 and I<> text are italic, C<> text and verbatim paragraphs are on light gray, and links are underlined. It uses a color when option base is given. Themes light and dark, for light and dark terminals, use a base color for headings, like App::mdee, and its tint for backgrounds. Theme none does not decorate, and the output looks the same as that of Pod::Text except for the above.

The background of a verbatim paragraph starts one column before the smallest indent of its lines. The text is not moved.

MULTI-COLUMN VIEW

Use nup as the pager to read a long document in multiple columns on a wide terminal:

export MANWIDTH=80
export MANPAGER='nup -AL --runlen=0'
perldoc -o fancy Some::Module

These variables are used by man(1) too. Option -L puts all the pages in one row, which is scrolled sideways, and -A disables pages when the terminal has room for only one column. --runlen=0 is given because lines are already folded by this module.

MANWIDTH is necessary, because the default is the width of the whole terminal, not of a column. A line may exceed it by up to 4 columns. If some lines are folded again in a column, use a smaller value such as 78.

The keys to move by columns, which -L sets up, need less(1) 661 or later. On macOS and Linux, brew install tecolicom/tap/app-nup installs nup together with a version of less customized for it, which keeps the columns aligned with the edge of the screen when scrolled sideways, and shows the whole page that has a match when searched. See "LESS INTEGRATION" in App::nup.

When perldoc is run by nup, its output is not a terminal, so give -w theme to decorate it:

nup -L perldoc -o fancy -w theme:quiet Some::Module

OPTIONS

In addition to the options of Pod::Text, the following are accepted. With perldoc, give them by the -w option, as in -w theme:dark.

theme => quiet | light | dark | none

Theme of decoration. Default is quiet. An unknown theme is an error.

base => color

Base color. Headings are in this color, and C<> text and verbatim paragraphs have the same background of its tint. Links have an underline of this color, if the terminal supports it. Default is RoyalBlue in themes light and dark, and none in theme quiet.

On a terminal without 24bit color, the tint is the palest of the 256 colors other than white, or dark gray in theme dark. 24bit color is used when COLORTERM is truecolor; see "ENVIRONMENT" in Term::ANSIColor::Concise.

A color name, such as RebeccaPurple, is adjusted to the brightness for the theme (=y50 for quiet, =y45 for light and =y65 for dark). Anything else, such as <RebeccaPurple>=y40, is used as is in Term::ANSIColor::Concise notation. An invalid color is an error.

wall => bool

Paint the background of the whole page with a tint of the base color, or with light gray in theme quiet without base. Default is false. With perldoc, give -w wall. Label wall in colormap works without this option.

colormap => { label => spec, ... }

Override the decoration of each label. spec is explained in "COLOR SPEC". With perldoc, give -w colormap:label=spec, which can be repeated. An empty spec means no decoration. An unknown label is an error. Theme none ignores the colormap.

These are the specs of the themes:

label      quiet   light                dark
-----      -----   -----                ----
head1      D       ${base}D             ${base}D
head2      D       ${base}D             ${base}D
head3      I       ${base}              ${base}
head4      I       ${base}I             ${base}I
bold       D       D                    D
italic     I       I                    I
code       (1)     L00/${tint}          L25/${tint}
file               I                    I
verbatim   (2)     /${tint};E           /${tint};E
link       U       U_${base}            U_${base}
wall       (3)     /${base}*s50=l97     /${base}*s25=l10

${tint}    L24     ${base}*s50=l93      ${base}*s25=l16

(1) K/${tint}  (2) K/${tint};E  (3) K/<gray97>

When base is given, theme quiet uses these instead:

head1      ${base}D
head2      ${base}D
head3      ${base}I
head4      ${base}I
link       U_${base}
wall       K/${base}*s50=l97
${tint}    ${base}*s50=l93

link is the text of L<>.

quotes

Same as Pod::Text, but the default is none with the themes other than none, which decorate C<> text.

COLOR SPEC

Decoration is written in the notation of Term::ANSIColor::Concise. This is the part of it used in the themes:

D  I  U         bold, italic, underline
R  G  B  K ...  red, green, blue, black ...
L00 .. L25      gray scale from black to white
<Coral>         color name
/               the color after it is for the background
_               the color after it is for the underline
E               paint the background to the end of line
;               separator, does nothing

In addition, these are replaced by the colors of the theme:

${base}         base color
${tint}         background color made from the base color

A color name and ${base} can be adjusted by modifiers after it:

=y50            set luminance (perceived brightness) to 50
=l97            set lightness to 97; 0 is black and 100 is white
=s100           set saturation to 100; 0 is gray
*s50            multiply saturation by 50%

Modifiers are applied from left to right. So these specs are read as:

${base}D            bold, in the base color
U_${base}           underline in the base color
/${tint};E          on the tint, painted to the end of line
K/${base}*s50=l97   black, on the base color with a half of
                    saturation and the lightness of 97, that is
                    almost white with a slight hue of it

On the command line, quote them from the shell:

perldoc -o fancy -w 'colormap:head1=${base}DU' Some::Module
perldoc -o fancy -w 'colormap:wall=K/<Coral>*s50=l95' Some::Module

METHODS

color_spec(label)

Returns the color spec of label, with ${base} and ${tint} expanded.

runin

Returns the width of run-in, 4. A line can exceed the width by this much.

BUGS

All text is folded by Text::ANSI::Fold, and Japanese line breaking rules also apply to ASCII punctuation, so %hash or :name may be split, and a line may exceed the width, which Pod::Text does not do.

Verbatim paragraphs are not folded, as in Pod::Text.

SEE ALSO

Pod::Perldoc::ToFancy, Pod::Text, Pod::Text::Termcap, Pod::Text::Color, Pod::Perldoc::ToTerm, Text::ANSI::Fold, Term::ANSIColor::Concise, App::nup, App::mdee

AUTHOR

Kazumasa Utashiro

LICENSE

Copyright © 2026 Kazumasa Utashiro.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.