| 1 | package Pod::Text::Fancy; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | our $VERSION = "0.02"; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use parent 'Pod::Text'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use List::Util qw(max min); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Text::ANSI::Fold qw(:constants); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Text::VisualWidth::PP (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Term::ANSIColor::Concise qw(ansi_color ansi_color_24 ansi_code); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # quotes: keep the quotes around C<> text. An empty or missing spec | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # means not decorated. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # adjust: added to the base color given by name. wall: used only with | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # option wall. tint: background of C<> text and verbatim paragraphs. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # Saturation is multiplied, so that gray is kept as gray. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # color256: used when 24bit color is not available. =s100=l93 always | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # becomes the palest color of 6x6x6 other than white. tint_gray is for | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # a gray base color, which has no hue. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | our %THEME = ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | none => { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | quotes => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | light => { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | adjust => q(=y45), | ||||||||||||||||||||||||||||||||||||||||||
| 29 | base => q(<RoyalBlue>=y45), | ||||||||||||||||||||||||||||||||||||||||||
| 30 | head1 => q(${base}D), | ||||||||||||||||||||||||||||||||||||||||||
| 31 | head2 => q(${base}D), | ||||||||||||||||||||||||||||||||||||||||||
| 32 | head3 => q(${base}), | ||||||||||||||||||||||||||||||||||||||||||
| 33 | head4 => q(${base}I), | ||||||||||||||||||||||||||||||||||||||||||
| 34 | bold => q(D), | ||||||||||||||||||||||||||||||||||||||||||
| 35 | italic => q(I), | ||||||||||||||||||||||||||||||||||||||||||
| 36 | tint => q(${base}*s50=l93), | ||||||||||||||||||||||||||||||||||||||||||
| 37 | code => q(L00/${tint}), | ||||||||||||||||||||||||||||||||||||||||||
| 38 | file => q(I), | ||||||||||||||||||||||||||||||||||||||||||
| 39 | verbatim => q(/${tint};E), | ||||||||||||||||||||||||||||||||||||||||||
| 40 | link => q(U_${base}), | ||||||||||||||||||||||||||||||||||||||||||
| 41 | wall => q(/${base}*s50=l97), | ||||||||||||||||||||||||||||||||||||||||||
| 42 | color256 => { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | tint => q(${base}=s100=l93), | ||||||||||||||||||||||||||||||||||||||||||
| 44 | tint_gray => q(L24), | ||||||||||||||||||||||||||||||||||||||||||
| 45 | wall => q(/L25), | ||||||||||||||||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | dark => { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | adjust => q(=y65), | ||||||||||||||||||||||||||||||||||||||||||
| 50 | base => q(<RoyalBlue>=y65), | ||||||||||||||||||||||||||||||||||||||||||
| 51 | head1 => q(${base}D), | ||||||||||||||||||||||||||||||||||||||||||
| 52 | head2 => q(${base}D), | ||||||||||||||||||||||||||||||||||||||||||
| 53 | head3 => q(${base}), | ||||||||||||||||||||||||||||||||||||||||||
| 54 | head4 => q(${base}I), | ||||||||||||||||||||||||||||||||||||||||||
| 55 | bold => q(D), | ||||||||||||||||||||||||||||||||||||||||||
| 56 | italic => q(I), | ||||||||||||||||||||||||||||||||||||||||||
| 57 | tint => q(${base}*s25=l16), | ||||||||||||||||||||||||||||||||||||||||||
| 58 | code => q(L25/${tint}), | ||||||||||||||||||||||||||||||||||||||||||
| 59 | file => q(I), | ||||||||||||||||||||||||||||||||||||||||||
| 60 | verbatim => q(/${tint};E), | ||||||||||||||||||||||||||||||||||||||||||
| 61 | link => q(U_${base}), | ||||||||||||||||||||||||||||||||||||||||||
| 62 | wall => q(/${base}*s25=l10), | ||||||||||||||||||||||||||||||||||||||||||
| 63 | color256 => { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | tint => q(L03), | ||||||||||||||||||||||||||||||||||||||||||
| 65 | wall => q(/L00), | ||||||||||||||||||||||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # Quiet decoration, by attributes and gray only. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | quiet => { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | head1 => q(D), | ||||||||||||||||||||||||||||||||||||||||||
| 71 | head2 => q(D), | ||||||||||||||||||||||||||||||||||||||||||
| 72 | head3 => q(I), | ||||||||||||||||||||||||||||||||||||||||||
| 73 | head4 => q(I), | ||||||||||||||||||||||||||||||||||||||||||
| 74 | bold => q(D), | ||||||||||||||||||||||||||||||||||||||||||
| 75 | italic => q(I), | ||||||||||||||||||||||||||||||||||||||||||
| 76 | tint => q(L24), | ||||||||||||||||||||||||||||||||||||||||||
| 77 | code => q(K/${tint}), | ||||||||||||||||||||||||||||||||||||||||||
| 78 | verbatim => q(K/${tint};E), | ||||||||||||||||||||||||||||||||||||||||||
| 79 | link => q(U), | ||||||||||||||||||||||||||||||||||||||||||
| 80 | wall => q(K/<gray97>), | ||||||||||||||||||||||||||||||||||||||||||
| 81 | color256 => { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | wall => q(K/L25), | ||||||||||||||||||||||||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # Used when the base color is given. The terminal can be light | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # or dark: y50 has enough contrast with both of them. | ||||||||||||||||||||||||||||||||||||||||||
| 86 | with_base => { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | adjust => q(=y50), | ||||||||||||||||||||||||||||||||||||||||||
| 88 | head1 => q(${base}D), | ||||||||||||||||||||||||||||||||||||||||||
| 89 | head2 => q(${base}D), | ||||||||||||||||||||||||||||||||||||||||||
| 90 | head3 => q(${base}I), | ||||||||||||||||||||||||||||||||||||||||||
| 91 | head4 => q(${base}I), | ||||||||||||||||||||||||||||||||||||||||||
| 92 | tint => q(${base}*s50=l93), | ||||||||||||||||||||||||||||||||||||||||||
| 93 | link => q(U_${base}), | ||||||||||||||||||||||||||||||||||||||||||
| 94 | wall => q(K/${base}*s50=l97), | ||||||||||||||||||||||||||||||||||||||||||
| 95 | color256 => { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | tint => q(${base}=s100=l93), | ||||||||||||||||||||||||||||||||||||||||||
| 97 | tint_gray => q(L24), | ||||||||||||||||||||||||||||||||||||||||||
| 98 | wall => q(K/L25), | ||||||||||||||||||||||||||||||||||||||||||
| 99 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | my %FANCY_OPTION = map { $_ => 1 } qw(theme colormap base wall); | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | my %LABEL = map { $_ => 1 } | |||||||||||||||||||||||||||||||||||||||||
| 107 | qw(head1 head2 head3 head4 bold italic code file verbatim link wall); | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | # The default theme is quiet. Theme none does not decorate. | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 548 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 548 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 548 | my %opt = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 548 | my %fancy = map { $_ => delete $opt{$_} } grep { exists $opt{$_} } keys %FANCY_OPTION; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 548 | ▶ | $fancy{colormap} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$fancy{"colormap"} //= {}
MC/DC100%1/1
$fancy{"colormap"} //= {}
$fancy{"colormap"}
Truth table100%2/2
A
A= $fancy{"colormap"}
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 548 | ▶ | $fancy{theme} //= q(quiet); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$fancy{"theme"} //= "quiet"
MC/DC100%1/1
$fancy{"theme"} //= "quiet"
$fancy{"theme"}
Truth table100%2/2
A
A= $fancy{"theme"}
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 548 | ▶ | my $theme = $THEME{$fancy{theme}} or croak "Unknown theme: $fancy{theme}"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 546 | for my $label (keys %{$fancy{colormap}}) { | |||||||||||||||||||||||||||||||||||||||||
| 118 | 8 | ▶ | croak "Unknown color label: $label" unless $LABEL{$label}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 545 | ▶ | if (defined $fancy{base}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 109 | ▶ | $theme = { %$theme, %{$theme->{with_base} // {}} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$theme->{"with_base"} // {}
MC/DC100%1/1
$theme->{"with_base"} // {}
$theme->{"with_base"}
Truth table100%2/2
A
A= $theme->{"with_base"}
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | $fancy{base} = "<$fancy{base}>" . ($theme->{adjust} // q()) | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 109 | ▶ | if $fancy{base} =~ /\A[A-Za-z]\w*\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$theme->{"adjust"} // ""
MC/DC100%1/1
$theme->{"adjust"} // ""
$theme->{"adjust"}
Truth table100%2/2
A
A= $theme->{"adjust"}
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | # It has to take modifiers to make a tint. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 109 | ▶ | eval { ansi_color("$fancy{base}=l50", q(x)); 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | or croak "Invalid base color: $fancy{base}"; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 436 | ▶ | $fancy{base} = $theme->{base} // q(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$theme->{"base"} // ""
MC/DC100%1/1
$theme->{"base"} // ""
$theme->{"base"}
Truth table100%2/2
A
A= $theme->{"base"}
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 543 | $fancy{spec} = $theme; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 543 | ▶ | $fancy{gray} = $fancy{base} ne q() && _is_gray($fancy{base}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$fancy{'base'} ne '' && _is_gray($fancy{'base'})
MC/DC100%2/2
$fancy{'base'} ne '' && _is_gray($fancy{'base'})
$fancy{'base'} ne ''
_is_gray($fancy{'base'})
Truth table100%3/3
A && B
A= $fancy{'base'} ne ''B= _is_gray($fancy{'base'})
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 543 | $fancy{color} = $fancy{theme} ne q(none); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 543 | ▶ | $opt{quotes} //= q(none) unless $theme->{quotes}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$opt{"quotes"} //= "none"
MC/DC100%1/1
$opt{"quotes"} //= "none"
$opt{"quotes"}
Truth table100%2/2
A
A= $opt{"quotes"}
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 543 | my $self = $class->SUPER::new(%opt); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 543 | $self->{FANCY} = \%fancy; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 543 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 176 | ▶ | sub _is_gray { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_gray: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 176 | ▶ | my ($r, $g, $b) = ansi_color_24(shift, q(x)) =~ /38;2;(\d+);(\d+);(\d+)/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | or return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 176 | ▶ | return $r == $g && $g == $b; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$r == $g && $g == $b
MC/DC100%2/2
$r == $g && $g == $b
$r == $g
$g == $b
Truth table100%3/3
A && B
A= $r == $gB= $g == $b
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | # Color spec of $label in Term::ANSIColor::Concise notation, with | ||||||||||||||||||||||||||||||||||||||||||
| 146 | # ${base} and ${tint} expanded. Empty if $label is not decorated. | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 2733 | ▶ | sub color_spec { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
color_spec: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 2733 | my ($self, $label) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 2733 | my $fancy = $self->{FANCY}; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 2733 | my %spec = %{$fancy->{spec}}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 2733 | ▶ | if (!$Term::ANSIColor::Concise::RGB24) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 912 | ▶ | %spec = (%spec, %{$spec{color256} // {}}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$spec{"color256"} // {}
MC/DC0%0/1
$spec{"color256"} // {}
$spec{"color256"}
Truth table50%1/2
A
A= $spec{"color256"}
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 912 | ▶ | $spec{tint} = $spec{tint_gray} if $fancy->{gray} && defined $spec{tint_gray}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$fancy->{"gray"} and defined $spec{"tint_gray"}
MC/DC100%2/2
$fancy->{"gray"} and defined $spec{"tint_gray"}
$fancy->{"gray"}
defined $spec{"tint_gray"}
Truth table100%3/3
A and B
A= $fancy->{"gray"}B= defined $spec{"tint_gray"}
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 2733 | ▶ | delete $spec{wall} unless $fancy->{wall}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 2733 | ▶ | my $spec = $fancy->{colormap}{$label} // $spec{$label} // q(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
($fancy->{"colormap"}{$label} // $spec{$label}) // ""
$fancy->{"colormap"}{$label} // $spec{$label}
MC/DC100%2/2
($fancy->{"colormap"}{$label} // $spec{$label}) // ""
$fancy->{"colormap"}{$label}
$spec{$label}
Truth table100%3/3
A // B
A= $fancy->{"colormap"}{$label}B= $spec{$label}
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 2733 | ▶ | $spec =~ s/\$\{tint\}/$spec{tint} \/\/ q()/ge; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$spec{"tint"} // ""
MC/DC0%0/1
$spec{"tint"} // ""
$spec{"tint"}
Truth table50%1/2
A
A= $spec{"tint"}
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 2733 | $spec =~ s/\$\{base\}/$fancy->{base}/g; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 2733 | return $spec; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 3016 | ▶ | sub _decorates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decorates: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 3016 | my ($self, $label) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 3016 | ▶ | return $self->{FANCY}{color} && $self->color_spec($label) ne q(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->{'FANCY'}{'color'} && $self->color_spec($label) ne ''
MC/DC100%2/2
$self->{'FANCY'}{'color'} && $self->color_spec($label) ne ''
$self->{'FANCY'}{'color'}
$self->color_spec($label) ne ''
Truth table100%3/3
A && B
A= $self->{'FANCY'}{'color'}B= $self->color_spec($label) ne ''
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 725 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 725 | my ($self, $label, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 725 | ▶ | return $text unless $self->_decorates($label); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 667 | return ansi_color($self->color_spec($label), $text); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 6 | for my $n (1 .. 4) { | |||||||||||||||||||||||||||||||||||||||||
| 174 | 24 | my $method = "cmd_head$n"; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 24 | my $super = Pod::Text->can($method); | |||||||||||||||||||||||||||||||||||||||||
| 176 | 6 | ▶ | no strict q(refs); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 24 | ▶ | *{$method} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 107 | my ($self, $attrs, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 107 | $text =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 107 | $super->($self, $attrs, $self->_paint("head$n", $text)); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 24 | }; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # Without color, fall back to Pod::Text (e.g. *italic*). | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | for my $pair ([ b => 'bold' ], [ i => 'italic' ], [ f => 'file' ]) { | |||||||||||||||||||||||||||||||||||||||||
| 186 | 18 | my ($code, $label) = @$pair; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 18 | my $method = "cmd_$code"; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 18 | my $super = Pod::Text->can($method); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 18 | ▶ | *{$method} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 467 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 467 | ▶ | return $super->($self, @_) unless $self->_decorates($label); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 268 | return $self->_paint($label => $_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 18 | }; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 121 | ▶ | sub cmd_c { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_c: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 121 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 121 | return $self->_paint(code => $self->SUPER::cmd_c(@_)); | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 164 | ▶ | sub cmd_l { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_l: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 164 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 164 | return $self->_paint(link => $self->SUPER::cmd_l(@_)); | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 32 | ▶ | sub cmd_verbatim { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_verbatim: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 32 | my ($self, $attrs, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 32 | ▶ | return $self->SUPER::cmd_verbatim($attrs, $text) unless $self->_decorates(q(verbatim)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 22 | ▶ | $self->item if defined $$self{ITEM}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 22 | ▶ | return if $text =~ /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 22 | $text =~ s/\s*$//; | |||||||||||||||||||||||||||||||||||||||||
| 213 | # Paint from a column before the smallest indent of the paragraph. | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # A verbatim paragraph is indented by at least a column, so there is | ||||||||||||||||||||||||||||||||||||||||||
| 215 | # always room for it. Paint blank lines too, not to break the | ||||||||||||||||||||||||||||||||||||||||||
| 216 | # background. | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 22 | my $indent = max(0, min(map { length } $text =~ /^(?!\h*$)( *)/mg) - 1); | |||||||||||||||||||||||||||||||||||||||||
| 218 | 22 | my $margin = q( ) x ($$self{MARGIN} + $indent); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 22 | $text =~ s{^ {0,$indent}(.*)$}{$margin . $self->_paint(verbatim => $1)}mge; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 22 | $self->output($text . "\n\n"); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 22 | return q(); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # Width of run-in (and run-out) for Japanese line breaking. A line may | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # exceed the folding width by this much when prohibited characters are | ||||||||||||||||||||||||||||||||||||||||||
| 226 | # hung at its end. | ||||||||||||||||||||||||||||||||||||||||||
| 227 | # Paint the background of the whole page. It has to be given again | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # after every reset. A line already filled to the right edge, that is | ||||||||||||||||||||||||||||||||||||||||||
| 229 | # verbatim, is left as it is there. | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 1792 | ▶ | sub output { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 1792 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 1792 | ▶ | return $self->SUPER::output(@_) unless $self->_decorates(q(wall)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 112 | my $bg = ansi_code($self->color_spec(q(wall))); | |||||||||||||||||||||||||||||||||||||||||
| 234 | 112 | my $text = join q(), @_; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 112 | $text =~ s{([^\n]*)\n}{ | |||||||||||||||||||||||||||||||||||||||||
| 236 | 132 | my $line = $1; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 132 | $line =~ s/\e\[K\e\[m\z//; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 132 | $line =~ s/\e\[m(?:\e\[K)?/\e[m$bg/g; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 132 | "$bg$line\e[K\e[m\n"; | |||||||||||||||||||||||||||||||||||||||||
| 240 | }ge; | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 112 | return $self->SUPER::output($text); | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 9 | ▶ | sub runin { 4 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
runin: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | # Wide characters written without spaces between words | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | ▶ | sub InConcatScript { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
InConcatScript: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | return <<"END"; | |||||||||||||||||||||||||||||||||||||||||
| 249 | +utf8::East_Asian_Width=Wide | ||||||||||||||||||||||||||||||||||||||||||
| 250 | +utf8::East_Asian_Width=Fullwidth | ||||||||||||||||||||||||||||||||||||||||||
| 251 | -utf8::Script=Hangul | ||||||||||||||||||||||||||||||||||||||||||
| 252 | END | ||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | ▶ | sub InFullwidthPunctuation { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
InFullwidthPunctuation: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 4 | return <<"END"; | |||||||||||||||||||||||||||||||||||||||||
| 257 | +utf8::East_Asian_Width=Wide | ||||||||||||||||||||||||||||||||||||||||||
| 258 | +utf8::East_Asian_Width=Fullwidth | ||||||||||||||||||||||||||||||||||||||||||
| 259 | &utf8::Punctuation | ||||||||||||||||||||||||||||||||||||||||||
| 260 | END | ||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | my $esc = qr/\e\[[\d;:]*[mK]/; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | # Remove line breaks in the source in the same way as ansifold --refill, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # before Pod::Text turns them into spaces. Escape sequences of | ||||||||||||||||||||||||||||||||||||||||||
| 267 | # decoration may sit next to the line break. | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 752 | ▶ | sub reformat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reformat: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 752 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 752 | local $_ = shift; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 752 | s/\p{InFullwidthPunctuation}$esc*\K\h*\n\h*//g; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 752 | s/\p{InConcatScript}$esc*\K\h*\n\h*(?=$esc*\p{InConcatScript})//g; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 752 | return $self->SUPER::reformat($_); | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 752 | ▶ | sub wrap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wrap: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 752 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 752 | local $_ = shift; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 752 | my $spaces = ' ' x $$self{MARGIN}; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 752 | my $width = $$self{opt_width} - $$self{MARGIN}; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 752 | ▶ | if ($width <= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $self->whine($self->line_count(), 'Margin is wider than the output width'); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $spaces = ''; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $width = $$self{opt_width}; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 752 | state $fold = Text::ANSI::Fold->new( | |||||||||||||||||||||||||||||||||||||||||
| 287 | boundary => 'space', | ||||||||||||||||||||||||||||||||||||||||||
| 288 | linebreak => LINEBREAK_ALL, | ||||||||||||||||||||||||||||||||||||||||||
| 289 | runin => runin(), | ||||||||||||||||||||||||||||||||||||||||||
| 290 | runout => runin(), | ||||||||||||||||||||||||||||||||||||||||||
| 291 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 752 | my @lines = $fold->configure(width => $width)->text($_)->chops; | |||||||||||||||||||||||||||||||||||||||||
| 293 | # Spaces can be followed by escape sequences to close decoration. | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 752 | s/[ \t]+(?=(?:$esc|[ \t])*$)//g for @lines; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 752 | my $output = join '', map { $spaces . $_ . "\n" } @lines; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 752 | ▶ | $output = $spaces unless @lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 752 | $output =~ s/\s+$/\n\n/; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 752 | return $output; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 54 | ▶ | sub strip_format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 54 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 54 | $text =~ s/\e\[[\d;:]*[mK]//g; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 54 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | # Copied from Pod::Text 6.1.1 item(), changing only how the length of | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # the tag is measured: use the display width instead of length(). | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 54 | ▶ | sub item { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
item: called CC=16 SCAR=32.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 54 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 54 | my $tag = $$self{ITEM}; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 54 | ▶ | unless (defined $tag) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | carp "Item called without tag"; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 54 | undef $$self{ITEM}; | |||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 54 | ▶ | my $indent = $$self{INDENTS}[-1] // $$self{opt_indent}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"INDENTS"}[-1] // $self->{"opt_indent"}
MC/DC0%0/2
$self->{"INDENTS"}[-1] // $self->{"opt_indent"}
$self->{"INDENTS"}[-1]
$self->{"opt_indent"}
Truth table33%1/3
A // B
A= $self->{"INDENTS"}[-1]B= $self->{"opt_indent"}
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 54 | my $margin = ' ' x $$self{opt_margin}; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 54 | my $tag_length = Text::VisualWidth::PP::width($self->strip_format($tag)); | |||||||||||||||||||||||||||||||||||||||||
| 321 | 54 | my $fits = ($$self{MARGIN} - $indent >= $tag_length + 1); | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 54 | ▶ | if (!$text || $text =~ /^\s+$/ || !$fits) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not $text or $text =~ /^\s+$/u or not $fits
not $text or $text =~ /^\s+$/u
MC/DC33%1/3
not $text or $text =~ /^\s+$/u or not $fits
not $text
$text =~ /^\s+$/u
not $fits
Truth table50%2/4
not(A) or B or not(C)
A= not $textB= $text =~ /^\s+$/uC= not $fits
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 44 | my $realindent = $$self{MARGIN}; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 44 | $$self{MARGIN} = $indent; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 44 | my $output = $self->reformat($tag); | |||||||||||||||||||||||||||||||||||||||||
| 327 | 44 | ▶ | $output =~ s/^$margin /$margin:/ if ($$self{opt_alt} && $indent > 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"opt_alt"} and $indent > 0
MC/DC0%0/2
$self->{"opt_alt"} and $indent > 0
$self->{"opt_alt"}
$indent > 0
Truth table33%1/3
A and B
A= $self->{"opt_alt"}B= $indent > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 44 | $output =~ s/\n*$/\n/; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 44 | ▶ | $output .= "\n" if $text && $text =~ /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$text and $text =~ /^\s*$/u
MC/DC0%0/2
$text and $text =~ /^\s*$/u
$text
$text =~ /^\s*$/u
Truth table33%1/3
A and B
A= $textB= $text =~ /^\s*$/u
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 44 | $self->output($output); | |||||||||||||||||||||||||||||||||||||||||
| 331 | 44 | $$self{MARGIN} = $realindent; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 44 | ▶ | $self->output($self->reformat($text)) if ($text && $text =~ /\S/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$text and $text =~ /\S/u
MC/DC0%0/2
$text and $text =~ /\S/u
$text
$text =~ /\S/u
Truth table33%1/3
A and B
A= $textB= $text =~ /\S/u
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 10 | my $space = ' ' x $indent; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 10 | ▶ | $space =~ s/^$margin /$margin:/ if $$self{opt_alt}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 10 | $text = $self->reformat($text); | |||||||||||||||||||||||||||||||||||||||||
| 337 | 10 | ▶ | $text =~ s/^$margin /$margin:/ if ($$self{opt_alt} && $indent > 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"opt_alt"} and $indent > 0
MC/DC0%0/2
$self->{"opt_alt"} and $indent > 0
$self->{"opt_alt"}
$indent > 0
Truth table33%1/3
A and B
A= $self->{"opt_alt"}B= $indent > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 10 | my $tagspace = ' ' x $tag_length; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 10 | ▶ | $text =~ s/^($space)$tagspace/$1$tag/ or warn "Bizarre space in item"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 10 | $self->output($text); | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 345 | __END__ | ||||||||||||||||||||||||||||||||||||||||||