[![Actions Status](https://github.com/tecolicom/Pod-Text-Fancy/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/tecolicom/Pod-Text-Fancy/actions?workflow=test) [![MetaCPAN Release](https://badge.fury.io/pl/Pod-Text-Fancy.svg)](https://metacpan.org/release/Pod-Text-Fancy)
# 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](https://metacpan.org/pod/Pod%3A%3AText) for reading POD
written in Japanese and other languages with wide characters.

<div>
    <p><img width="1000" src="https://raw.githubusercontent.com/tecolicom/Pod-Text-Fancy/main/images/perldoc.png"></p>
</div>

It differs from Pod::Text in the following.

- Folding by display width

    Text is folded by [Text::ANSI::Fold](https://metacpan.org/pod/Text%3A%3AANSI%3A%3AFold), 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 are removed,
    instead of being turned into a space.

- 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](https://metacpan.org/pod/App%3A%3Amdee), 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](https://metacpan.org/pod/App%3A%3Anup) 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)](http://man.he.net/man1/man) 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.

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](https://metacpan.org/pod/Pod%3A%3AText), the following are accepted.
With [perldoc](https://metacpan.org/pod/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](https://metacpan.org/pod/Term%3A%3AANSIColor%3A%3AConcise#ENVIRONMENT).

    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](https://metacpan.org/pod/Term%3A%3AANSIColor%3A%3AConcise) 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"](#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](https://metacpan.org/pod/Term%3A%3AANSIColor%3A%3AConcise).
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](https://metacpan.org/pod/Text%3A%3AANSI%3A%3AFold), 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.

Text::ANSI::Fold 2.41 takes only ASCII and Latin characters as word
characters, and a no-break space as a white space.  This module
overrides it while folding, so that words in other scripts such as
Cyrillic and Greek are not split, and a line does not break at a
no-break space from `S<>`.

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

# SEE ALSO

[Pod::Perldoc::ToFancy](https://metacpan.org/pod/Pod%3A%3APerldoc%3A%3AToFancy),
[Pod::Text](https://metacpan.org/pod/Pod%3A%3AText), [Pod::Text::Termcap](https://metacpan.org/pod/Pod%3A%3AText%3A%3ATermcap), [Pod::Text::Color](https://metacpan.org/pod/Pod%3A%3AText%3A%3AColor),
[Pod::Perldoc::ToTerm](https://metacpan.org/pod/Pod%3A%3APerldoc%3A%3AToTerm),
[Text::ANSI::Fold](https://metacpan.org/pod/Text%3A%3AANSI%3A%3AFold), [Term::ANSIColor::Concise](https://metacpan.org/pod/Term%3A%3AANSIColor%3A%3AConcise),
[App::nup](https://metacpan.org/pod/App%3A%3Anup), [App::mdee](https://metacpan.org/pod/App%3A%3Amdee)

# 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.
