lib/App/ansicolumn.pm

filter: Statementstmt 93.0% 738 / 793 Branchbran 82.6% 253 / 306 Conditioncond 71.4% 155 / 217 MC/DCmcdc 47.5% 58 / 122 Subroutinesub 86.4% 70 / 81 Podpod 0.0% 0 / 16 totaltotal 83.0% 1274 / 1535 CC 265 SCAR 31.8
CC
265
Cov
87%
table_out
70.1
setup_options
47.6
parallel_out
19.1
CRAP 24.0
↑ Summary lib/App/ansicolumn/Table.pm »
1 package App::ansicolumn;
2  
3 297 our $VERSION = "1.71";
4  
5 297 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 297 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 297 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 297 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 297 ▶use open IO => 'utf8', ':std';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 297 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 297 ▶use Getopt::EX::Long qw(:DEFAULT Configure ExConfigure);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 297 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 297 ▶use List::Util qw(max sum min any);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 297 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 297 ▶use Text::ANSI::Fold qw(ansi_fold);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 297 ▶use Text::ANSI::Fold::Util qw(ansi_width);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 297 ▶use Text::ANSI::Printf qw(ansi_printf ansi_sprintf);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 297 ▶use App::ansicolumn::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 297 ▶use App::ansicolumn::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 297 ▶use App::ansicolumn::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 297 ▶use App::ansicolumn::Border;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 297 ▶use Getopt::EX::RPN qw(rpn_calc);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 297 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 297 our @EXPORT_OK = qw(ansicolumn);
27  
28 # --intact: what joins the lines to be kept intact into one line
29 # (UNIT SEPARATOR, for now)
30 297 our $INTACT_SEP = "\x1F";
31 # --intact: what joins the lines of a group, kept intact in one pane,
32 # and the marks of its lines: RECORD SEPARATOR on the first line and
33 # GROUP SEPARATOR on the others
34 297 our $GROUP_SEP = "\x1D";
35 297 our $GROUP_FIRST = "\x1E";
36 297 our $GROUP_MARK = qr/[\x1D\x1E]/;
37  
38 295 ▶sub ansicolumn {
Subroutine ansicolumn: called CC=1 SCAR=0.0
Pod undocumented
39 295 __PACKAGE__->new->perform(@_);
40 }
41  
42 297 my %DEFAULT_COLORMAP = (
43 BORDER => '',
44 BORDER_LABEL => '',
45 TEXT => '',
46 );
47  
48 297 ▶use Getopt::EX::Hashed 1.0701; {
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 297 Getopt::EX::Hashed->configure( DEFAULT => [ is => 'rw' ] );
51  
52 297 has debug => ' ' ;
53 297 has help => ' h ' ;
54 297 has version => ' v ' ;
55 297 has width => ' =s w c ' ;
56 297 has fillrows => ' x ' ;
57 297 has table => ' t ' ;
58 297 has table_columns_limit => ' =i l ' , default => -1 ;
59 297 has table_align => ' ! A ' ;
60 297 has table_tabs => ' + T ' ;
61 297 has table_right => ' =s R ' , default => '' ;
62 297 has table_center => ' =s ' , default => '' ;
63 297 has item_format => ' =s ' , default => '' ;
64 297 has table_wrap_mark => ' =s ' , default => '' ;
65 297 has table_cell_mark => ' =s ' , default => '' ;
66 297 has table_head => ' =i ' , default => 0 ;
67 297 has table_remove => ' =s K ' , default => '' ;
68 297 has table_squeeze => ' ! ' ;
69 297 has table_tight => ' ! ' , default => 1 ;
70 297 has padding => ' ! ' ;
71 297 has separator => ' =s s ' , default => ' ' ;
72 297 has regex_sep => ' r ' ;
73 297 has output_separator => ' =s o ' , default => ' ' ;
74 297 has document => ' ! D ' ;
75 297 has parallel => ' ! V ' ;
76 297 has filename => ' ! H ' ;
77 297 has filename_format => ' =s ' , default => ': %s';
78 297 has ignore_empty => ' ! I ' , default => 0 ;
79 297 has pages => ' ! ' ;
80 297 has up => ' :s U ' ;
81 297 has page => ' :i P ' , min => 0;
82 0 ▶ has no_page => ' ' , action => sub { $_->page = undef } ;
Subroutine __ANON__: not called CC=1 SCAR=1.2
83 297 has pane => ' =s C ' , default => 0 ;
84 297 has cell => ' =s X ' ;
85 297 has pane_width => ' =s S pw ' ;
86 297 has widen => ' ! W ' ;
87 297 has paragraph => ' ! p ' ;
88 297 has height => ' =s ' , default => 0 ;
89 297 has column_unit => ' =i cu ' , min => 1, default => 8 ;
90 297 has margin => ' =i ' , min => 0, default => 1 ;
91 297 has tabstop => ' =i ' , min => 1, default => 8 ;
92 297 has tabhead => ' =s ' ;
93 297 has tabspace => ' =s ' ;
94 297 has tabstyle => ' :s ts ' ;
95 297 has ignore_space => ' ! is ' , default => 1 ;
96 297 has linestyle => ' =s ls ' , default => '' ;
97 297 has boundary => ' =s ' , default => '' ;
98 297 has linebreak => ' =s lb ' , default => '' ;
99 297 has runin => ' =i ' , min => 0, default => 2 ;
100 297 has runout => ' =i ' , min => 0, default => 2 ;
101 297 has runlen => ' =i ' ;
102 297 has pagebreak => ' ! ' , default => 1 ;
103 297 has intact => ' ! ' ;
104 0 ▶ has border => ' :s ' ; has B => '' , action => sub { $_->border = '' } ;
Subroutine __ANON__: not called CC=1 SCAR=0.4
105 15 ▶ has no_border => ' ' , action => sub { $_->border = 'none' } ;
Subroutine __ANON__: called CC=1 SCAR=0.0
106 297 has border_style => ' =s bs ' , default => 'box' ;
107 297 has label => ' =s% ' , default => {} ;
108 297 has page_label => ' =s% ' , default => {} ;
109 297 has mark => ' =s% ' , default => {} ;
110 297 has white_space => ' ! ' , default => 2 ;
111 297 has isolation => ' ! ' , default => 2 ;
112 0 ▶ has fillup => ' :s ' ; has F => '' , action => sub { $_->fillup = '' } ;
Subroutine __ANON__: not called CC=1 SCAR=0.4
113 297 has fillup_str => ' :s ' , default => '' ;
114 297 has ambiguous => ' =s ' , default => 'narrow' ;
115 297 has discard_el => ' ! ' , default => 1 ;
116 297 has padchar => ' =s ' , default => ' ' ;
117 297 has colormap => ' =s@ cm ' , default => [] ;
118 297 has factotum => ' =s@ ' , default => [] ;
119 297 has highlight => ' :s hi ' , action => \&_highlight ;
120 1 ▶ has no_highlight => ' ' , action => sub { $_->highlight = undef } ;
Subroutine __ANON__: called CC=1 SCAR=0.0
121 4 ▶ has no_hi => ' ' , action => sub { $_->highlight = undef } ;
Subroutine __ANON__: called CC=1 SCAR=0.0
122  
123 297 has '+boundary' => any => [ qw(none word space) ] ;
124 297 has '+linestyle' => any => [ qw(none wordwrap wrap truncate) ] ;
125 297 has '+fillup' => any => [ qw(pane page none), '' ] ;
126 297 has '+ambiguous' => any => [ qw(wide narrow) ] ;
127  
128 # --2up .. --9up
129 0 ▶ my $nup = sub { $_[0] =~ /^(\d+)/ and $_->up = $1 } ;
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^(\d+)/u and $_->up = $1 0 0 0
130 297 for my $n (2..9) {
131 2376 has "${n}up" => '', action => $nup;
132 }
133  
134 # for run-time use
135 297 has span => ;
136 297 has panes => ;
137 297 has border_height => ;
138 297 has current_page => ;
139 297 has _bl => ;
140 297 has _pbl => ;
141 297 has _mk => ;
142 297 has _total_panes => ;
143 297 has _cell_fold => ; # cells wrapped by the table mode, by width
144 297 has _total_pages => ;
145  
146 297 Getopt::EX::Hashed->configure( DEFAULT => [] );
147  
148 0 ▶ has '+help' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
149 0 pod2usage
150 -verbose => 99,
151 -sections => [ qw(SYNOPSIS VERSION) ];
152 297 };
153  
154 0 ▶ has '+version' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
155 0 say "Version: $VERSION";
156 0 exit;
157 297 };
158  
159 ### RPN calc for --height, --width, --pane, --up, --pane-width
160 339 ▶ has [ qw(+height +width +pane +up +pane_width) ] => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
161 339 my $obj = $_;
162 339 my($name, $val) = @_;
163 339 $val =~ s/^=//; # -w=2/, as ansifold takes it
164 339 ▶ $obj->$name = $val !~ /\D/ ? $val : do {
Branch: 1 branch
BranchTrueFalseTotal
!($val =~ /\D/u) ? : 333 6 339
165 6 ▶ my $init = $name =~ /height/ ? $obj->term_height : $obj->term_width;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /height/u ? : 0 6 6
166 6 ▶ rpn_calc($init, $val) // die "$val: invalid $name.\n";
Condition50%1/2
rpn_calc($init, $val) // die("${val}: invalid $name.\n")
l!l
60
MC/DC0%0/1
rpn_calc($init, $val) // die("${val}: invalid $name.\n")
rpn_calc($init, $val)
Truth table50%1/2
A
A= rpn_calc($init, $val)
Aresult
11
00
167 };
168 297 };
169  
170 ### --ambiguous=wide
171 0 ▶ has '+ambiguous' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
172 0 ▶ if ($_[1] eq 'wide') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] eq "wide") 0 0 0
173 0 $Text::VisualWidth::PP::EastAsian = 1;
174 0 Text::ANSI::Fold->configure(ambiguous => 'wide');
175 }
176 297 };
177  
178 ### --runlen
179 0 ▶ has '+runlen' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
180 0 $_->runin = $_->runout = $_[1];
181 297 };
182  
183 ### --tabstop, --tabstyle
184 0 ▶ has [ qw(+tabstop +tabstyle) ] => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
185 0 my($name, $val) = map "$_", @_;
186 0 ▶ if ($val eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq "") 0 0 0
187 0 list_tabstyle();
188 0 exit;
189 }
190 0 Text::ANSI::Fold->configure($name => $val);
191 297 };
192  
193 ### --tabhead, --tabspace
194 297 ▶ use charnames ':loose';
Subroutine BEGIN: called CC=1 SCAR=0.0
195 0 ▶ has [ qw(+tabhead +tabspace) ] => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
196 0 my($name, $c) = map "$_", @_;
197 0 ▶ $c = charnames::string_vianame($c) || die "$c: invalid name\n"
Branch: 1 branch
BranchTrueFalseTotal
if length $c > 1 0 0 0
Condition0%0/2
charnames::string_vianame($c) || die("${c}: invalid name\n")
l!l
00
MC/DC0%0/1
charnames::string_vianame($c) || die("${c}: invalid name\n")
charnames::string_vianame($c)
Truth table0%0/2
A
A= charnames::string_vianame($c)
Aresult
11
00
198 if length($c) > 1;
199 0 Text::ANSI::Fold->configure($name => $c);
200 297 };
201  
202 ### -A
203 3 ▶ has '+table_align' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
204 3 ▶ if ($_->table_align = $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->table_align = $_[1]) 3 0 3
205 3 $_->table = $_[1];
206 }
207 297 };
208 ### -T, -TT
209 1 ▶ has '+table_tabs' => sub {
Subroutine __ANON__: called CC=3 SCAR=15.1
210 # incremental behavior
211 1 $_->table_tabs += $_[1];
212 1 ▶ if ($_->table_tabs == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_->table_tabs == 1) { } 1 0 1
elsif ($_->table_tabs == 2) { } 0 0 0
213 # enable -t and -A
214 1 $_->table = $_->table_align = $_[1];
215 } elsif ($_->table_tabs == 2) {
216 # set -rs '\t+'
217 0 $_->regex_sep = 1;
218 0 $_->separator = '\\t+';
219 }
220 297 };
221  
222 297 has TERM_SIZE => ;
223 297 has COLORHASH => default => { %DEFAULT_COLORMAP };
224 297 has COLORLIST => default => [];
225 297 has COLOR => ;
226 297 has BORDER => ;
227  
228 297 ▶} no Getopt::EX::Hashed;
Subroutine BEGIN: called CC=1 SCAR=0.0
229  
230 0 ▶sub list_tabstyle {
Subroutine list_tabstyle: not called CC=2 SCAR=17.9
Pod undocumented
231 0 my %style = %Text::ANSI::Fold::TABSTYLE;
232 0 my $max = max map length, keys %style;
233 0 for my $name (sort keys %style) {
234 0 my($head, $space) = @{$style{$name}};
235 0 printf "%*s %s%s\n", $max, $name, $head, $space x 7;
236 }
237 }
238  
239 # --highlight[=NAME]: the value is optional, so Getopt::Long takes
240 # the word after the option for it. When the word is a file and not
241 # the name of a highlighter, it is given back to be read as a file.
242 23 ▶sub _highlight {
Subroutine _highlight: called CC=4 SCAR=13.9
243 23 my $obj = $_;
244 23 my($name, $value) = @_;
245 23 ▶ if ($value ne '' and not _highlighter($value) and -e $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value ne "" and not _highlighter($value) and -e $value) 3 20 23
Condition100%6/6
$value ne "" and not _highlighter($value) and -e $value
!ll&&!rl&&r
1913
$value ne "" and not _highlighter($value)
!ll&&!rl&&r
1094
MC/DC100%3/3
$value ne "" and not _highlighter($value) and -e $value
$value ne "" not _highlighter($value) -e $value
Truth table100%4/4
A and not(B) and C
A= $value ne ""B= not _highlighter($value)C= -e $value
ABCresult
0XX0
10X0
1100
1111
246 3 unshift @ARGV, $value;
247 3 $value = '';
248 }
249 23 $obj->highlight = $value;
250 }
251  
252 # The name of a highlighter of Text::ANSI::Highlight, or its short name
253 13 ▶sub _highlighter {
Subroutine _highlighter: called CC=2 SCAR=7.0
254 13 my $name = shift;
255 13 ▶ eval { require Text::ANSI::Highlight; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Text::ANSI::Highlight; 1 } } and defined "Text::ANSI::Highlight"->highlighter($name) 13 0 13
256 and defined Text::ANSI::Highlight->highlighter($name);
257 }
258  
259 295 ▶sub perform {
Subroutine perform: called CC=14 SCAR=26.7
Pod undocumented
260 295 my $obj = shift;
261 295 local @ARGV = decode_argv(@_);
262 295 ExConfigure BASECLASS => [ __PACKAGE__, "Getopt::EX" ];
263 295 Configure qw(bundling no_auto_abbrev no_ignore_case);
264 295 ▶ $obj->getopt || pod2usage(2);
Branch: 1 branch
BranchTrueFalseTotal
$obj->getopt or pod2usage(2) 295 0 295
265  
266 295 $obj->setup_options;
267  
268 # --mark: an unknown name is an error, with or without a label
269 295 $obj->_marks;
270  
271 # The files are read through IO::Factotum when it is loaded
272 # (read_files), and this is the only place which knows what it
273 # reads them through.
274 #
275 # --factotum: converters of IO::Factotum, by their names.
276 294 my @names = map { split /,/ } @{$obj->factotum};
277 294 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 4 290 294
278 4 ▶ eval { require IO::Factotum; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require IO::Factotum; 1 } } or die "--factotum requires IO::Factotum. " 4 0 4
279 or die "--factotum requires IO::Factotum.\n";
280 4 IO::Factotum::load(@names);
281 }
282 # --highlight[=NAME]: Text::ANSI::Highlight::IO gives the
283 # highlighter of the name to IO::Factotum, the default one without
284 # the name.
285 293 ▶ if (defined(my $name = $obj->highlight)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $obj->highlight)) 20 273 293
286 20 ▶ eval { require Text::ANSI::Highlight::IO; 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Text::ANSI::Highlight::IO; 1 } } or die "--highlight requires Text::ANSI::Highlight::IO. " 20 0 20
287 or die "--highlight requires Text::ANSI::Highlight::IO.\n";
288 20 ▶ eval { Text::ANSI::Highlight::IO->setup($name eq '' ? () : $name); 1 }
Branch: 2 branches
BranchTrueFalseTotal
eval { do { "Text::ANSI::Highlight::IO"->setup($name eq "" ? () : $name); 1 } } or die $@ =~ s/ at .* line \d+\.?\n\z/\n/ru 19 1 20
$name eq '' ? : 12 8 20
289 or die $@ =~ s/ at .* line \d+\.?\n\z/\n/r;
290 }
291  
292 292 ▶ warn Dumper $obj if $obj->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->debug 0 292 292
293  
294 292 ▶ my @files = $obj->read_files(@ARGV ? @ARGV : '-') or return 1;
Branch: 2 branches
BranchTrueFalseTotal
my(@files) = $obj->read_files(@ARGV ? @ARGV : "-") or return 1 290 0 290
@ARGV ? : 45 247 292
295  
296 290 ▶ if ($obj->ignore_empty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->ignore_empty) 0 290 290
297 0 @files = grep { not $_->is_empty } @files;
298 }
299  
300 290 ▶ if ($obj->table) {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->table) { } 163 127 290
elsif ($obj->parallel) { } 20 107 127
301 163 my @lines = map { $_->lines } @files;
302 163 $obj->table_out(@lines);
303 }
304 elsif ($obj->parallel) {
305 20 $obj->parallel_out(@files);
306 }
307 else {
308 107 $obj->nup_out(@files);
309 }
310  
311 290 return 0
312 }
313  
314 295 ▶sub setup_options {
Subroutine setup_options: called CC=30 SCAR=38.6
Pod undocumented
315 295 my $obj = shift;
316  
317 ## --parallel or @ARGV > 1
318 295 ▶ if ($obj->parallel //= @ARGV > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->parallel //= @ARGV > 1) 20 275 295
Condition100%2/2
$obj->parallel //= @ARGV > 1
l!l
19276
MC/DC100%1/1
$obj->parallel //= @ARGV > 1
$obj->parallel
Truth table100%2/2
A
A= $obj->parallel
Aresult
11
00
319 20 ▶ $obj->linestyle ||= 'wrap';
Condition50%1/2
$obj->linestyle ||= "wrap"
l!l
020
MC/DC0%0/1
$obj->linestyle ||= "wrap"
$obj->linestyle
Truth table50%1/2
A
A= $obj->linestyle
Aresult
11
00
320 20 ▶ $obj->widen //= 1;
Condition50%1/2
$obj->widen //= 1
l!l
020
MC/DC0%0/1
$obj->widen //= 1
$obj->widen
Truth table50%1/2
A
A= $obj->widen
Aresult
11
00
321 20 ▶ $obj->border //= '';
Condition100%2/2
$obj->border //= ""
l!l
155
MC/DC100%1/1
$obj->border //= ""
$obj->border
Truth table100%2/2
A
A= $obj->border
Aresult
11
00
322 }
323  
324 ## --border takes optional border-style value
325 295 ▶ if (defined(my $border = $obj->border)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $border = $obj->border)) 57 238 295
326 57 ▶ if ($border ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($border ne "") 32 25 57
327 32 $obj->border_style = $border;
328 }
329 57 $obj->border = 1;
330 57 ▶ $obj->fillup //= 'pane';
Condition100%2/2
$obj->fillup //= "pane"
l!l
354
MC/DC100%1/1
$obj->fillup //= "pane"
$obj->fillup
Truth table100%2/2
A
A= $obj->fillup
Aresult
11
00
331 }
332  
333 ## --linestyle
334 295 ▶ if ($obj->linestyle eq 'wordwrap') {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->linestyle eq "wordwrap") 0 295 295
335 0 $obj->linestyle = 'wrap';
336 0 $obj->boundary = 'word';
337 }
338  
339 ## -P
340 295 ▶ if (defined $obj->page) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->page) 34 261 295
341 34 ▶ $obj->widen = 1 if $obj->pane and not $obj->pane_width;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->pane and not $obj->pane_width 26 8 34
Condition66%2/3
$obj->pane and not $obj->pane_width
!ll&&!rl&&r
8026
MC/DC50%1/2
$obj->pane and not $obj->pane_width
$obj->pane not $obj->pane_width
Truth table66%2/3
A and not(B)
A= $obj->paneB= not $obj->pane_width
ABresult
0X0
100
111
342 34 ▶ $obj->height ||= $obj->page || $obj->term_height - 1;
Condition33%2/6
$obj->height ||= $obj->page || $obj->term_height - 1
l!l&&r!l&&!r
0340
$obj->page || $obj->term_height - 1
l!l&&r!l&&!r
3400
MC/DC0%0/3
$obj->height ||= $obj->page || $obj->term_height - 1
$obj->height $obj->page $obj->term_height - 1
Truth table0%0/4
A ||= B || C
A= $obj->heightB= $obj->pageC= $obj->term_height - 1
ABCresult
1XX1
01X1
0011
0000
343 34 ▶ $obj->linestyle ||= 'wrap';
Condition50%1/2
$obj->linestyle ||= "wrap"
l!l
034
MC/DC0%0/1
$obj->linestyle ||= "wrap"
$obj->linestyle
Truth table50%1/2
A
A= $obj->linestyle
Aresult
11
00
344 34 ▶ $obj->border //= 1;
Condition100%2/2
$obj->border //= 1
l!l
286
MC/DC100%1/1
$obj->border //= 1
$obj->border
Truth table100%2/2
A
A= $obj->border
Aresult
11
00
345 34 ▶ $obj->fillup //= 'pane';
Condition100%2/2
$obj->fillup //= "pane"
l!l
286
MC/DC100%1/1
$obj->fillup //= "pane"
$obj->fillup
Truth table100%2/2
A
A= $obj->fillup
Aresult
11
00
346 }
347  
348 ## -U
349 295 ▶ if ($obj->up) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->up) 0 295 295
350 0 $obj->pane = $obj->up;
351 0 $obj->widen = 1;
352 0 ▶ $obj->linestyle ||= 'wrap';
Condition0%0/2
$obj->linestyle ||= "wrap"
l!l
00
MC/DC0%0/1
$obj->linestyle ||= "wrap"
$obj->linestyle
Truth table0%0/2
A
A= $obj->linestyle
Aresult
11
00
353 0 ▶ $obj->border //= 1;
Condition0%0/2
$obj->border //= 1
l!l
00
MC/DC0%0/1
$obj->border //= 1
$obj->border
Truth table0%0/2
A
A= $obj->border
Aresult
11
00
354 0 ▶ $obj->fillup //= 'pane';
Condition0%0/2
$obj->fillup //= "pane"
l!l
00
MC/DC0%0/1
$obj->fillup //= "pane"
$obj->fillup
Truth table0%0/2
A
A= $obj->fillup
Aresult
11
00
355 }
356  
357 ## -D
358 295 ▶ if ($obj->document) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->document) 20 275 295
359 20 $obj->widen = 1;
360 20 ▶ $obj->linebreak ||= 'all';
Condition50%1/2
$obj->linebreak ||= "all"
l!l
020
MC/DC0%0/1
$obj->linebreak ||= "all"
$obj->linebreak
Truth table50%1/2
A
A= $obj->linebreak
Aresult
11
00
361 20 ▶ $obj->linestyle ||= 'wrap';
Condition100%2/2
$obj->linestyle ||= "wrap"
l!l
515
MC/DC100%1/1
$obj->linestyle ||= "wrap"
$obj->linestyle
Truth table100%2/2
A
A= $obj->linestyle
Aresult
11
00
362 20 ▶ $obj->boundary ||= 'word';
Condition50%1/2
$obj->boundary ||= "word"
l!l
020
MC/DC0%0/1
$obj->boundary ||= "word"
$obj->boundary
Truth table50%1/2
A
A= $obj->boundary
Aresult
11
00
363 20 ▶ $obj->white_space = 0 if $obj->white_space > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->white_space > 1 20 0 20
364 20 ▶ $obj->isolation = 0 if $obj->isolation > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->isolation > 1 20 0 20
365 }
366  
367 ## --colormap
368 297 ▶ use Getopt::EX::Colormap;
Subroutine BEGIN: called CC=1 SCAR=0.0
369 my $cm = Getopt::EX::Colormap
370 ->new(HASH => $obj->{COLORHASH}, LIST => $obj->{COLORLIST})
371 295 ->load_params(@{$obj->colormap});
372 295 ▶ $obj->{COLOR} = sub { $cm->color(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
373  
374 ## --border
375 295 ▶ if ($obj->border) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->border) 63 232 295
376 63 my $style = $obj->border_style;
377 63 ▶ ($obj->{BORDER} = App::ansicolumn::Border->new)
Condition50%1/2
($obj->{"BORDER"} = "App::ansicolumn::Border"->new)->style($style) // die("${style}: Unknown style.\n")
l!l
630
MC/DC0%0/1
($obj->{"BORDER"} = "App::ansicolumn::Border"->new)->style($style) // die("${style}: Unknown style.\n")
($obj->{"BORDER"} = "App::ansicolumn::Border"->new)->style($style)
Truth table50%1/2
A
A= ($obj->{"BORDER"} = "App::ansicolumn::Border"->new)->style($style)
Aresult
11
00
378 ->style($style) // die "$style: Unknown style.\n";
379 }
380  
381 295 $obj;
382 }
383  
384 3982 ▶sub color {
Subroutine color: called CC=1 SCAR=0.0
Pod undocumented
385 3982 my $obj = shift;
386 3982 $obj->{COLOR}->(@_);
387 }
388  
389 20 ▶sub parallel_out {
Subroutine parallel_out: called CC=16 SCAR=29.5
Pod undocumented
390 20 my $obj = shift;
391 20 my @files = @_;
392  
393 20 my $max_line_length = max map { $_->width } @files;
394 20 ▶ $obj->pane ||= @files;
Condition66%2/3
$obj->pane ||= @files
l!l&&r!l&&!r
8120
MC/DC0%0/2
$obj->pane ||= @files
$obj->pane @files
Truth table66%2/3
A ||= B
A= $obj->paneB= @files
ABresult
1X1
011
000
395 20 $obj->set_horizontal($max_line_length);
396  
397 # calculate span and set for each file
398 20 ▶ if (my $cell = $obj->cell) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cell = $obj->cell) 1 19 20
399 1 my @spans = split /,+/, $cell;
400 1 for my $i (keys @files) {
401 2 ▶ my $span = $spans[$i] // $spans[-1];
Condition33%1/3
$spans[$i] // $spans[-1]
l!l&&r!l&&!r
200
MC/DC0%0/2
$spans[$i] // $spans[-1]
$spans[$i] $spans[-1]
Truth table33%1/3
A // B
A= $spans[$i]B= $spans[-1]
ABresult
1X1
011
000
402 2 ▶ if ($span =~ /^[-+]/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($span =~ /^[-+]/u) { } 0 2 2
elsif ($span =~ s/^(<=|[<=])//u) { } 0 2 2
elsif (not $span =~ /^\d+$/u) { } 0 2 2
403 0 $span += $obj->{span};
404 0 ▶ $span < 0 and die "Invalid number: $cell\n";
Branch: 1 branch
BranchTrueFalseTotal
$span < 0 and die "Invalid number: $cell\n" 0 0 0
405 }
406 elsif ($span =~ s/^(<=|[<=])//) {
407 0 my $length = $files[$i]->width;
408 0 ▶ $span = $span ? min($length, $span) : $length;
Branch: 1 branch
BranchTrueFalseTotal
$span ? : 0 0 0
409 }
410 elsif ($span !~ /^\d+$/) {
411 0 die "Invalid number: $cell\n";
412 }
413 2 $files[$i]->span($span);
414 }
415 }
416 20 $obj->set_contents($_) for @files;
417 # the files are not laid out in panes: no group is kept in one
418 20 ▶ if ($obj->intact) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->intact) 1 19 20
419 1 ▶ $_->replace(sub { $_[0] =~ s/^$GROUP_MARK//r }) for @files;
Subroutine __ANON__: called CC=1 SCAR=0.0
420 }
421 # for the labels: every file is a pane
422 20 $obj->{_total_panes} = @files;
423 20 $obj->{_total_pages} = roundup(scalar @files, $obj->pane) / $obj->pane;
424 20 my $column_out = $obj->_column_out;
425 20 ▶ for ($obj->current_page = 0; @files; $obj->current_page++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) 21 20 41
426 21 my @rows = splice @files, 0, $obj->pane;
427 21 my @data = map { [ $_->lines ] } @rows;
428 21 my $max_length = max map { int @$_ } @data;
429 21 ▶ my @span = map { $_->span // $obj->span } @rows;
Condition66%2/3
$_->span // $obj->span
l!l&&r!l&&!r
2390
MC/DC0%0/2
$_->span // $obj->span
$_->span $obj->span
Truth table66%2/3
A // B
A= $_->spanB= $obj->span
ABresult
1X1
011
000
430 21 ▶ if ($obj->filename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->filename) 3 18 21
431 3 my $w = $obj->span + $obj->border_width('center');
432 my $format = join '', (
433 (map {
434 3 my $w = $_ + $obj->border_width('center');
435 3 "%-${w}.${w}s";
436 } @span[0..$#span-1]),
437 "%s\n");
438 ansi_printf $format, map {
439 3 ansi_sprintf $obj->filename_format, $_->name;
440 } @rows;
441 }
442 $column_out->({ span => \@span, names => [ map $_->name, @rows ] },
443 map {
444 21 push @$_, (($obj->fillup_str) x ($max_length - @$_));
445 41 $_;
446 } @data);
447 }
448 20 return $obj;
449 }
450  
451 107 ▶sub nup_out {
Subroutine nup_out: called CC=3 SCAR=11.0
Pod undocumented
452 107 my $obj = shift;
453 107 my @files = @_;
454 107 my $max_length = max map { $_->width } @files;
455 107 $obj->set_horizontal($max_length);
456 107 for my $file (@files) {
457 108 ▶ next if $file->is_empty;
Branch: 1 branch
BranchTrueFalseTotal
if $file->is_empty 3 105 108
458 105 my $page = clone($obj)->set_contents($file);
459 105 my @data;
460 105 $page->set_vertical([ $file->lines ])
461 ->set_layout(\@data, $file->parts);
462 105 $page->page_out($file->name, @data);
463 }
464 107 return $obj;
465 }
466  
467 292 ▶sub read_files {
Subroutine read_files: called CC=11 SCAR=24.5
Pod undocumented
468 292 my $obj = shift;
469 # The content is divided at formfeeds where a formfeed is a break.
470 # It is not with --no-pagebreak, and in the table and the parallel
471 # view, where the panes are not filled: the formfeeds are left in
472 # the text there. --pages divides it in any case, and makes a
473 # file of every part.
474 292 ▶ my $divide = $obj->pages ||
Condition100%9/9
$obj->pages || $obj->pagebreak && !$obj->parallel && !$obj->table
l!l&&r!l&&!r
9107176
$obj->pagebreak and not $obj->parallel and not $obj->table
!ll&&!rl&&r
13163107
$obj->pagebreak and not $obj->parallel
!ll&&!rl&&r
112270
MC/DC100%4/4
$obj->pages || $obj->pagebreak && !$obj->parallel && !$obj->table
$obj->pages $obj->pagebreak not $obj->parallel not $obj->table
Truth table100%5/5
A || B and not(C) and not(D)
A= $obj->pagesB= $obj->pagebreakC= not $obj->parallelD= not $obj->table
ABCDresult
1XXX1
01111
00XX0
010X0
01100
475 ($obj->pagebreak && !$obj->parallel && !$obj->table);
476 292 my @files;
477 # When IO::Factotum is loaded (--factotum=NAME), the files
478 # are opened by it, and those which a converter takes are read
479 # through that converter. The names stay as they are.
480 292 my $factotum = IO::Factotum->can('open_input');
481 292 for my $file (@_) {
482 303 my $fh;
483 303 ▶ if ($factotum) {
Branch: 1 branch
BranchTrueFalseTotal
if ($factotum) { } 34 269 303
484 34 ▶ $fh = $factotum->($file) or die "$file: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh = &$factotum($file) or die "${file}: $!" 32 2 34
485 32 binmode $fh, ':utf8';
486 } else {
487 269 ▶ open $fh, $file or die "$file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $file or die "${file}: $!" 269 0 269
488 }
489 301 ▶ my $content = do { local $/; <$fh> } // do {
Condition33%1/3
do { local $/; readline $fh } // do { warn "${file}: $!\n" if $!; next }
l!l&&r!l&&!r
30100
MC/DC0%0/2
do { local $/; readline $fh } // do { warn "${file}: $!\n" if $!; next }
do { local $/; readline $fh } do { warn "${file}: $!\n" if $!; next }
Truth table33%1/3
A // B
A= do { local $/; readline $fh }B= do { warn "${file}: $!\n" if $!; next }
ABresult
1X1
011
000
490 0 ▶ warn "$file: $!\n" if $!;
Branch: 1 branch
BranchTrueFalseTotal
if $! 0 0 0
491 0 next;
492 };
493 301 my $doc = App::ansicolumn::Document->new(
494 name => $file,
495 text => $content,
496 formfeed => $divide,
497 keep_ls => $obj->table,
498 );
499 301 ▶ push @files, map { $obj->prepare($_) }
Branch: 1 branch
BranchTrueFalseTotal
$obj->pages ? : 9 292 301
500 $obj->pages ? $doc->pages : $doc;
501 }
502 290 @files;
503 }
504  
505 #
506 # Make the lines of a document ready to be laid out, and find the
507 # width of the longest.
508 #
509 312 ▶sub prepare {
Subroutine prepare: called CC=6 SCAR=17.9
Pod undocumented
510 312 my $obj = shift;
511 312 my $doc = shift;
512 312 ▶ my $intact = $obj->intact && !$obj->table;
Condition100%3/3
$obj->intact && !$obj->table
!ll&&!rl&&r
297114
MC/DC100%2/2
$obj->intact && !$obj->table
$obj->intact !$obj->table
Truth table100%3/3
A && not(B)
A= $obj->intactB= !$obj->table
ABresult
0X0
100
111
513 # -p: an empty line between the lines given, before the lines joined
514 # for --intact are divided, so that none goes in a table or a group
515 312 ▶ $doc->filter(\&insert_space) if $obj->paragraph;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->paragraph 1 311 312
516 # --intact: a line which has the separator holds lines to be kept
517 # intact, joined into one; it is divided into them, and every one
518 # keeps the separator at its start as its mark, until the line is
519 # folded (set_contents)
520 #
521 # A line which has GROUP SEPARATOR holds a group: lines kept intact
522 # and kept in one pane. Every line of it has the mark of a group
523 # after the separator: GROUP_FIRST on the first, GROUP_SEP on the
524 # others, until the layout (space_layout).
525 14 ▶ $doc->filter(sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
526 map {
527 14 ▶ if (/$GROUP_SEP/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/$App::ansicolumn::GROUP_SEP/u) { } 8 44 52
elsif (/$App::ansicolumn::INTACT_SEP/u) { } 6 38 44
528 8 my @l = split /$GROUP_SEP/, $_, -1;
529 8 ▶ map { $INTACT_SEP . ($_ ? $GROUP_SEP : $GROUP_FIRST) . $l[$_] } keys @l;
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 14 8 22
530 }
531 elsif (/$INTACT_SEP/) {
532 6 map("$INTACT_SEP$_", split /$INTACT_SEP/, $_, -1);
533 }
534 38 else { $_ }
535 } @_;
536 312 ▶ }) if $intact;
Branch: 1 branch
BranchTrueFalseTotal
if $intact 14 298 312
537 312 my @width;
538 312 ▶ if ($obj->table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->table) { } 163 149 312
539 163 @width = map { length } $doc->lines;
540 } else {
541 2023 ▶ $doc->replace(sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
542 2023 my $line = shift;
543 2023 ▶ my $mark = $intact && $line =~ s/^$INTACT_SEP//;
Condition100%3/3
$intact && $line =~ s/^$App::ansicolumn::INTACT_SEP//u
!ll&&!rl&&r
19503835
MC/DC100%2/2
$intact && $line =~ s/^$App::ansicolumn::INTACT_SEP//u
$intact $line =~ s/^$App::ansicolumn::INTACT_SEP//u
Truth table100%3/3
A && B
A= $intactB= $line =~ s/^$App::ansicolumn::INTACT_SEP//u
ABresult
0X0
100
111
544 2023 ▶ my $group = $mark && $line =~ s/^($GROUP_MARK)// ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$mark && $line =~ s/^($App::ansicolumn::GROUP_MARK)//u ? : 22 2001 2023
Condition100%3/3
$mark and $line =~ s/^($App::ansicolumn::GROUP_MARK)//u
!ll&&!rl&&r
19881322
MC/DC100%2/2
$mark and $line =~ s/^($App::ansicolumn::GROUP_MARK)//u
$mark $line =~ s/^($App::ansicolumn::GROUP_MARK)//u
Truth table100%3/3
A and B
A= $markB= $line =~ s/^($App::ansicolumn::GROUP_MARK)//u
ABresult
0X0
100
111
545 2023 my($text, $width) = $obj->expand_tab($line);
546 2023 push @width, $width;
547 2023 ▶ $mark ? "$INTACT_SEP$group$text" : $text;
Branch: 1 branch
BranchTrueFalseTotal
$mark ? : 35 1988 2023
548 149 });
549 }
550 312 ▶ $doc->width(max(@width) // 0);
Condition100%2/2
&max(@width) // 0
l!l
3066
MC/DC100%1/1
&max(@width) // 0
&max(@width)
Truth table100%2/2
A
A= &max(@width)
Aresult
11
00
551 312 $doc;
552 }
553  
554 #
555 # Expand the tabs in a line. Returns the line and its width.
556 #
557 2023 ▶sub expand_tab {
Subroutine expand_tab: called CC=6 SCAR=18.0
Pod undocumented
558 2023 my $obj = shift;
559 2023 my $text = shift;
560 2023 my($result, $width) = ('', 0);
561 2023 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$text ne "" and do { do { () = ansi_fold($text, -1, "expand", 1); $result .= $folded; $width = $w if $w > $width; $result .= $1 if $rest =~ s/^(\f+)//u; $rest eq "" or $rest ne $text or die sprintf("Text is not consumed, at %s (please report this).\n", $rest =~ s/([^\x20-\x7e])/sprintf "\x{%02x}", ord $1;/egru); $text = $rest } } 2 2023 2025
562 2025 my($folded, $rest, $w) = ansi_fold $text, -1, expand => 1;
563 2025 $result .= $folded;
564 2025 ▶ $width = $w if $w > $width;
Branch: 1 branch
BranchTrueFalseTotal
if $w > $width 1923 102 2025
565 # ansi_fold stops before formfeeds in the middle of the text
566 2025 ▶ $result .= $1 if $rest =~ s/^(\f+)//;
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ s/^(\f+)//u 2 2023 2025
567 # every turn must take something from the text; otherwise
568 # this loop never ends
569 2025 ▶ $rest eq '' or $rest ne $text or die sprintf
Branch: 1 branch
BranchTrueFalseTotal
$rest eq "" or $rest ne $text or die sprintf("Text is not consumed, at %s (please report this).\n", $rest =~ s/([^\x20-\x7e])/sprintf "\x{%02x}", ord $1;/egru) 2025 0 2025
Condition66%2/3
$rest eq "" or $rest ne $text
l!l&&r!l&&!r
202320
MC/DC0%0/2
$rest eq "" or $rest ne $text
$rest eq "" $rest ne $text
Truth table66%2/3
A or B
A= $rest eq ""B= $rest ne $text
ABresult
1X1
011
000
570 "Text is not consumed, at %s (please report this).\n",
571 0 $rest =~ s/([^\x20-\x7e])/sprintf '\\x{%02x}', ord $1/ger;
572 2025 $text = $rest;
573 } while ($text ne '');
574 2023 ($result, $width);
575 }
576  
577 127 ▶sub set_horizontal {
Subroutine set_horizontal: called CC=11 SCAR=24.2
Pod undocumented
578 127 my $obj = shift;
579 127 my $max_data_length = shift;
580  
581 297 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
582 127 my $width = $obj->get_width - $obj->border_width(qw(left right));
583 127 ▶ my $unit = $obj->column_unit // 1;
Condition50%1/2
$obj->column_unit // 1
l!l
1270
MC/DC0%0/1
$obj->column_unit // 1
$obj->column_unit
Truth table50%1/2
A
A= $obj->column_unit
Aresult
11
00
584  
585 127 my $span;
586 my $panes;
587 127 ▶ my $claim = sum($max_data_length,
Condition66%2/3
$obj->border_width('center') || $obj->margin
l!l&&r!l&&!r
30970
MC/DC0%0/2
$obj->border_width('center') || $obj->margin
$obj->border_width('center') $obj->margin
Truth table66%2/3
A || B
A= $obj->border_width('center')B= $obj->margin
ABresult
1X1
011
000
588 $obj->runin_margin,
589 $obj->border_width('center') || $obj->margin);
590 127 ▶ if ($obj->widen and not $obj->pane_width) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->widen and not $obj->pane_width) { } 59 68 127
Condition100%3/3
$obj->widen and not $obj->pane_width
!ll&&!rl&&r
66259
MC/DC100%2/2
$obj->widen and not $obj->pane_width
$obj->widen not $obj->pane_width
Truth table100%3/3
A and not(B)
A= $obj->widenB= not $obj->pane_width
ABresult
0X0
100
111
591 59 ▶ $panes = $obj->pane || $width / $claim || 1;
Condition80%4/5
$obj->pane || $width / $claim || 1
l!l
581
$obj->pane or $width / $claim
l!l&&r!l&&!r
5801
MC/DC50%1/2
$obj->pane || $width / $claim || 1
$obj->pane $width / $claim
Truth table66%2/3
A or B
A= $obj->paneB= $width / $claim
ABresult
1X1
011
000
592 59 $span = ($width + $obj->border_width('center')) / $panes;
593 } else {
594 68 ▶ $span = $obj->pane_width || roundup($claim, $unit);
Condition66%2/3
$obj->pane_width || &roundup($claim, $unit)
l!l&&r!l&&!r
18500
MC/DC0%0/2
$obj->pane_width || &roundup($claim, $unit)
$obj->pane_width &roundup($claim, $unit)
Truth table66%2/3
A || B
A= $obj->pane_widthB= &roundup($claim, $unit)
ABresult
1X1
011
000
595 68 ▶ $panes = $obj->pane || $width / $span || 1;
Condition100%5/5
$obj->pane || $width / $span || 1
l!l
671
$obj->pane or $width / $span
l!l&&r!l&&!r
48191
MC/DC100%2/2
$obj->pane || $width / $span || 1
$obj->pane $width / $span
Truth table100%3/3
A or B
A= $obj->paneB= $width / $span
ABresult
1X1
011
000
596 }
597 127 $span -= $obj->border_width('center');
598 127 ▶ $span < 1 and die "Not enough space.\n";
Branch: 1 branch
BranchTrueFalseTotal
$span < 1 and die "Not enough space. " 0 127 127
599  
600 127 ($obj->span, $obj->panes) = ($span, $panes);
601  
602 127 return $obj;
603 }
604  
605 146 ▶sub set_contents {
Subroutine set_contents: called CC=9 SCAR=22.0
Pod undocumented
606 146 my $obj = shift;
607 146 my $fp = shift;
608 146 ▶ (my $cell_width = $obj->span) < 1
Branch: 1 branch
BranchTrueFalseTotal
(my $cell_width = $obj->span) < 1 and die "Not enough space. " 0 146 146
609 and die "Not enough space.\n";
610 # Fold long lines
611 146 ▶ my $intact = $obj->intact && !$obj->table;
Condition66%2/3
$obj->intact && !$obj->table
!ll&&!rl&&r
132014
MC/DC50%1/2
$obj->intact && !$obj->table
$obj->intact !$obj->table
Truth table66%2/3
A && not(B)
A= $obj->intactB= !$obj->table
ABresult
0X0
100
111
612 146 ▶ if ($obj->linestyle and $obj->linestyle ne 'none') {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->linestyle and $obj->linestyle ne 'none') { } 93 53 146
elsif ($intact) { } 7 46 53
Condition66%2/3
$obj->linestyle and $obj->linestyle ne "none"
!ll&&!rl&&r
53093
MC/DC50%1/2
$obj->linestyle and $obj->linestyle ne "none"
$obj->linestyle $obj->linestyle ne "none"
Truth table66%2/3
A and B
A= $obj->linestyleB= $obj->linestyle ne "none"
ABresult
0X0
100
111
613 93 ▶ my $w = $fp->span // $cell_width;
Condition66%2/3
$fp->span // $cell_width
l!l&&r!l&&!r
2910
MC/DC0%0/2
$fp->span // $cell_width
$fp->span $cell_width
Truth table66%2/3
A // B
A= $fp->spanB= $cell_width
ABresult
1X1
011
000
614 93 ▶ my $fold = $obj->foldsub($w) or die;
Branch: 1 branch
BranchTrueFalseTotal
my $fold = $obj->foldsub($w) or die 93 0 93
615 93 ▶ if ($intact) {
Branch: 1 branch
BranchTrueFalseTotal
if ($intact) 7 86 93
616 # A line kept intact is laid out as it is: the room kept for
617 # run-in characters, word boundaries and line-break (kinsoku)
618 # rules are for text folded into lines. One that fits the
619 # pane is not folded, and a wider one is cut at the pane
620 # width, as a terminal does with a long line.
621 7 my $intact_fold = $obj->foldobj($w);
622 7 $intact_fold->configure(
623 margin => 0,
624 boundary => '',
625 linebreak => Text::ANSI::Fold::LINEBREAK_NONE,
626 );
627 7 my $line_fold = $fold;
628 7 my $truncate = $obj->linestyle eq 'truncate';
629 28 ▶ $fold = sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
630 28 my $line = shift;
631 28 ▶ $line =~ s/^$INTACT_SEP// or return $line_fold->($line);
Branch: 1 branch
BranchTrueFalseTotal
$line =~ s/^$App::ansicolumn::INTACT_SEP//u or return &$line_fold($line) 14 14 28
632 14 ▶ my $group = $line =~ s/^($GROUP_MARK)// ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$line =~ s/^($App::ansicolumn::GROUP_MARK)//u ? : 7 7 14
633 14 my @chops = $intact_fold->text($line)->chops;
634 14 ▶ @chops = $chops[0] if $truncate;
Branch: 1 branch
BranchTrueFalseTotal
if $truncate 5 9 14
635 # a line folded from a line of a group is in the group
636 14 ▶ return @chops if $group eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $group eq "" 7 7 14
637 7 ▶ map { ($_ ? $GROUP_SEP : $group) . $chops[$_] } keys @chops;
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 1 7 8
638 7 };
639 }
640 93 $fp->replace($fold);
641 }
642 elsif ($intact) {
643 # the mark of a group stays, for the layout
644 7 ▶ $fp->replace(sub { $_[0] =~ s/^$INTACT_SEP//r });
Subroutine __ANON__: called CC=1 SCAR=0.0
645 }
646 146 return $obj;
647 }
648  
649 105 ▶sub set_vertical {
Subroutine set_vertical: called CC=3 SCAR=11.1
Pod undocumented
650 105 my $obj = shift;
651 105 my $dp = shift;
652 105 $obj->border_height = do {
653 210 sum map { length > 0 }
654 105 map { $obj->get_border($_) }
655 qw(top bottom);
656 };
657 105 ▶ $obj->height ||= div(int @$dp, $obj->panes) + $obj->border_height;
Condition66%2/3
$obj->height ||= div(int @$dp, $obj->panes) + $obj->border_height
l!l&&r!l&&!r
58470
MC/DC0%0/2
$obj->height ||= div(int @$dp, $obj->panes) + $obj->border_height
$obj->height div(int @$dp, $obj->panes) + $obj->border_height
Truth table66%2/3
A ||= B
A= $obj->heightB= div(int @$dp, $obj->panes) + $obj->border_height
ABresult
1X1
011
000
658 105 ▶ die "Not enough height.\n" if $obj->effective_height <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->effective_height <= 0 0 105 105
659 105 return $obj;
660 }
661  
662 105 ▶sub page_out {
Subroutine page_out: called CC=6 SCAR=17.9
Pod undocumented
663 105 my $obj = shift;
664 105 my $name = shift;
665 # for the labels: the numbers of all the pages and the panes. A
666 # page is filled by panes, or by rows with --fillrows; the last
667 # one has the panes which the rest of the lines take.
668 {
669 105 my($lines, $panes, $height) = (scalar @_, $obj->panes, $obj->effective_height);
670 105 my $pages = roundup($lines, $panes * $height) / ($panes * $height);
671 105 my $rest = $lines - ($pages - 1) * $panes * $height;
672 105 ▶ my $last = $pages == 0 ? 0
Branch: 2 branches
BranchTrueFalseTotal
$pages == 0 ? : 0 105 105
$obj->fillrows ? : 1 104 105
673 : $obj->fillrows ? min($panes, $rest)
674 : roundup($rest, $height) / $height;
675 105 $obj->{_total_pages} = $pages;
676 105 ▶ $obj->{_total_panes} = $pages == 0 ? 0 : ($pages - 1) * $panes + $last;
Branch: 1 branch
BranchTrueFalseTotal
$pages == 0 ? : 0 105 105
677 }
678 105 my $column_out = $obj->_column_out;
679 105 ▶ for ($obj->current_page = 0; @_; $obj->current_page++) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 244 105 349
680 244 my @columns = grep { @$_ } do {
681 244 ▶ if ($obj->fillrows) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->fillrows) { } 1 243 244
682 1 xpose map { [ splice @_, 0, $obj->panes ] } 1 .. $obj->effective_height;
683 } else {
684 243 map { [ splice @_, 0, $obj->effective_height ] } 1 .. $obj->panes;
685 }
686 };
687 244 $column_out->({ names => [($name) x scalar @columns] }, @columns);
688 }
689 105 return $obj;
690 }
691  
692 1125 ▶sub color_border {
Subroutine color_border: called CC=1 SCAR=0.0
Pod undocumented
693 1125 my $obj = shift;
694 1125 $obj->color('BORDER', $obj->get_border(@_));
695 }
696  
697 250 ▶sub _parse_labels {
Subroutine _parse_labels: called CC=7 SCAR=19.8
698 250 my $hash = shift;
699 250 ▶ return 0 unless %$hash;
Branch: 1 branch
BranchTrueFalseTotal
unless %$hash 231 19 250
700 19 my %result;
701 19 ▶ while (my($key, $s) = each %$hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hash) 26 19 45
702 26 ▶ next unless defined $s and $s ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and $s ne "" 0 26 26
Condition33%1/3
defined $s and $s ne ""
!ll&&!rl&&r
0026
MC/DC0%0/2
defined $s and $s ne ""
defined $s $s ne ""
Truth table33%1/3
A and B
A= defined $sB= $s ne ""
ABresult
0X0
100
111
703 26 my $offset;
704 26 ▶ if ($s =~ s/@(\d+)$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ s/@(\d+)$//u) 0 26 26
705 0 $offset = $1 + 0;
706 }
707 # the marks are empty where there is nothing in that direction,
708 # and a label left with no text by them is not shown
709 26 my $marked = $s =~ /%[LRUD]/;
710 26 $s =~ s/%n/%1\$d/g;
711 26 $s =~ s/%p/%2\$d/g;
712 26 $s =~ s/%f/%3\$s/g;
713 26 $s =~ s/%F/%4\$s/g;
714 26 $s =~ s/%N/%5\$d/g;
715 26 $s =~ s/%P/%6\$d/g;
716 26 $s =~ s/%L/%7\$s/g;
717 26 $s =~ s/%R/%8\$s/g;
718 26 $s =~ s/%U/%9\$s/g;
719 26 $s =~ s/%D/%10\$s/g;
720 26 $result{lc $key} = [ $offset, $s, $marked ];
721 }
722 19 ▶ %result ? \%result : 0;
Branch: 1 branch
BranchTrueFalseTotal
%result ? : 19 0 19
723 }
724  
725 # The marks of --label for the directions with something there, set
726 # by --mark
727 297 my %MARK = (
728 LEFT => '<', RIGHT => '>', UP => '^', DOWN => 'v',
729 # where there is nothing in that direction
730 LEFT_END => '', RIGHT_END => '', UP_END => '', DOWN_END => '',
731 );
732  
733 464 ▶sub _marks {
Subroutine _marks: called CC=4 SCAR=13.9
734 464 my $obj = shift;
735 464 ▶ $obj->{_mk} //= do {
Condition100%3/3
$obj->{"_mk"} //= do { my(%mark) = %MARK; while (() = each %{$obj->mark;}) { do { exists $mark{uc $name} or die "${name}: unknown mark\n"; $mark{uc $name} = $text }; } ; \%mark }
l!l&&r!l&&!r
1692941
MC/DC100%2/2
$obj->{"_mk"} //= do { my(%mark) = %MARK; while (() = each %{$obj->mark;}) { do { exists $mark{uc $name} or die "${name}: unknown mark\n"; $mark{uc $name} = $text }; } ; \%mark }
$obj->{"_mk"} do { my(%mark) = %MARK; while (() = each %{$obj->mark;}) { do { exists $mark{uc $name} or die "${name}: unknown mark\n"; $mark{uc $name} = $text }; } ; \%mark }
Truth table100%3/3
A //= B
A= $obj->{"_mk"}B= do { my(%mark) = %MARK; while (() = each %{$obj->mark;}) { do { exists $mark{uc $name} or die "${name}: unknown mark\n"; $mark{uc $name} = $text }; } ; \%mark }
ABresult
1X1
011
000
736 295 my %mark = %MARK;
737 295 ▶ while (my($name, $text) = each %{$obj->mark}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$obj->mark;}) 21 294 315
738 21 ▶ exists $mark{uc $name} or die "$name: unknown mark\n";
Branch: 1 branch
BranchTrueFalseTotal
exists $mark{uc $name} or die "${name}: unknown mark\n" 20 1 21
739 20 $mark{uc $name} = $text;
740 }
741 294 \%mark;
742 };
743 }
744  
745 # What a label has besides the numbers of the pane and the page: the
746 # numbers of all the panes and pages, and the marks. $p is the page
747 # (from 1), $i the pane in the row (from 0) of $npanes panes; a label
748 # of the page has no pane, and no mark for the left and the right.
749 169 ▶sub _label_more {
Subroutine _label_more: called CC=9 SCAR=22.1
750 169 my($obj, $p, $i, $npanes) = @_;
751 169 my $mark = $obj->_marks;
752 169 ▶ my $pages = $obj->{_total_pages} // 0;
Condition50%1/2
$obj->{"_total_pages"} // 0
l!l
1690
MC/DC0%0/1
$obj->{"_total_pages"} // 0
$obj->{"_total_pages"}
Truth table50%1/2
A
A= $obj->{"_total_pages"}
Aresult
11
00
753 [ $obj->{_total_panes} // 0, $pages,
754 (!defined $i ? '' : $i > 0 ? $mark->{LEFT} : $mark->{LEFT_END}),
755 (!defined $i ? '' : $i < $npanes - 1 ? $mark->{RIGHT} : $mark->{RIGHT_END}),
756 ($p > 1 ? $mark->{UP} : $mark->{UP_END}),
757 169 ▶ ($p < $pages ? $mark->{DOWN} : $mark->{DOWN_END}) ];
Branch: 6 branches
BranchTrueFalseTotal
!defined($i) ? : 16 153 169
$i > 0 ? : 19 134 153
!defined($i) ? : 16 153 169
$i < $npanes - 1 ? : 19 134 153
$p > 1 ? : 134 35 169
$p < $pages ? : 147 22 169
Condition50%1/2
$obj->{"_total_panes"} // 0
l!l
1690
MC/DC0%0/1
$obj->{"_total_panes"} // 0
$obj->{"_total_panes"}
Truth table50%1/2
A
A= $obj->{"_total_panes"}
Aresult
11
00
758 }
759  
760 # Overlay labels onto a border line string.
761 # $fs/$fe: fill region start/end.
762 # $ml/$mr: border margin accessible via @0.
763 # $n/$p: pane number / page number for sprintf expansion.
764 # $file: filename (path as given) - used as %3$s (basename) and %4$s (path as given).
765 # $more: the numbers of all the panes and pages (%N, %P), and the
766 # marks for the left, right, up and down (%L, %R, %U, %D), each empty
767 # where there is nothing in that direction.
768 169 ▶sub _overlay_labels {
Subroutine _overlay_labels: called CC=15 SCAR=27.7
769 169 my($obj, $str, $fs, $fe, $ml, $mr, $n, $p, $file, $more, $left, $center, $right) = @_;
770 297 ▶ use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
771 297 ▶ use Text::ANSI::Fold::Util qw(ansi_substr);
Subroutine BEGIN: called CC=1 SCAR=0.0
772 169 ▶ my $base = defined $file ? basename($file) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $file ? : 169 0 169
773 169 for my $item (
774 5 ▶ [ $left, sub { $fs - $ml + ($_[0] // $ml) } ],
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
$_[0] // $ml
l!l&&r!l&&!r
050
MC/DC0%0/2
$_[0] // $ml
$_[0] $ml
Truth table33%1/3
A // B
A= $_[0]B= $ml
ABresult
1X1
011
000
775 8 ▶ [ $right, sub { $fe + $mr - ($_[0] // $mr) - $_[1] } ],
Subroutine __ANON__: called CC=2 SCAR=9.2
Condition33%1/3
$_[0] // $mr
l!l&&r!l&&!r
080
MC/DC0%0/2
$_[0] // $mr
$_[0] $mr
Truth table33%1/3
A // B
A= $_[0]B= $mr
ABresult
1X1
011
000
776 240 ▶ [ $center, sub { $fs + int(($fe - $fs - $_[1]) / 2) } ],
Subroutine __ANON__: called CC=1 SCAR=0.0
777 ) {
778 507 my($spec, $pos_fn) = @$item;
779 507 ▶ next unless $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless $spec 327 180 507
780 180 my $fmt = $spec->[1];
781 180 ▶ next unless defined $fmt && $fmt ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fmt and $fmt ne "" 0 180 180
Condition33%1/3
defined $fmt and $fmt ne ""
!ll&&!rl&&r
00180
MC/DC0%0/2
defined $fmt and $fmt ne ""
defined $fmt $fmt ne ""
Truth table33%1/3
A and B
A= defined $fmtB= $fmt ne ""
ABresult
0X0
100
111
782 180 ▶ my $text = $fmt =~ /%/ ? sprintf($fmt, $n, $p, $base, $file // '', @$more) : $fmt;
Branch: 1 branch
BranchTrueFalseTotal
$fmt =~ /%/u ? : 177 3 180
Condition50%1/2
$file // ""
l!l
1770
MC/DC0%0/1
$file // ""
$file
Truth table50%1/2
A
A= $file
Aresult
11
00
783 180 ▶ next if $spec->[2] and $text !~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $spec->[2] and not $text =~ /\S/u 22 158 180
Condition100%3/3
$spec->[2] and not $text =~ /\S/u
!ll&&!rl&&r
1332522
MC/DC100%2/2
$spec->[2] and not $text =~ /\S/u
$spec->[2] not $text =~ /\S/u
Truth table100%3/3
A and not(B)
A= $spec->[2]B= not $text =~ /\S/u
ABresult
0X0
100
111
784 158 my $lw = ansi_width($text);
785 158 my $pos = $pos_fn->($spec->[0], $lw);
786 # A label in the middle grows to the left first, when its number
787 # gets a digit more, then to the right, and so on. It is placed
788 # from the narrowest one, that of the first pane and page: a
789 # label longer than that by one is longer on the left.
790 158 ▶ if ($spec == ($center // 0) and $fmt =~ /%/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec == ($center // 0) and $fmt =~ /%/u) 142 16 158
Condition100%5/5
$spec == ($center // 0) and $fmt =~ /%/u
!ll&&!rl&&r
133142
$center // 0
l!l
14513
MC/DC100%2/2
$spec == ($center // 0) and $fmt =~ /%/u
$spec == ($center // 0) $fmt =~ /%/u
MC/DC100%1/1
$center // 0
$center
Truth table100%3/3
A and B
A= $spec == ($center // 0)B= $fmt =~ /%/u
ABresult
0X0
100
111
Truth table100%2/2
A
A= $center
Aresult
11
00
791 142 ▶ my $narrow = ansi_width(sprintf $fmt, 1, 1, $base, $file // '', @$more);
Condition50%1/2
$file // ""
l!l
1420
MC/DC0%0/1
$file // ""
$file
Truth table50%1/2
A
A= $file
Aresult
11
00
792 142 ▶ $pos = $pos_fn->($spec->[0], $narrow) - int(($lw - $narrow + 1) / 2)
Branch: 1 branch
BranchTrueFalseTotal
if $lw > $narrow 95 47 142
793 if $lw > $narrow;
794 }
795 158 my $label = $obj->color('BORDER_LABEL', $text);
796 158 $str = ansi_substr($str, $pos, $lw, $label);
797 }
798 169 $str;
799 }
800  
801 125 ▶sub _column_out {
Subroutine _column_out: called CC=15 SCAR=27.2
802 125 my $obj = shift;
803  
804 125 my %bd = map { $_ => $obj->get_border($_) } qw(top bottom);
805  
806 125 ▶ my $bl = $obj->{_bl} //= _parse_labels($obj->label);
Condition33%1/3
$obj->{"_bl"} //= _parse_labels($obj->label)
l!l&&r!l&&!r
01250
MC/DC0%0/2
$obj->{"_bl"} //= _parse_labels($obj->label)
$obj->{"_bl"} _parse_labels($obj->label)
Truth table33%1/3
A //= B
A= $obj->{"_bl"}B= _parse_labels($obj->label)
ABresult
1X1
011
000
807 125 ▶ my $pbl = $obj->{_pbl} //= _parse_labels($obj->page_label);
Condition33%1/3
$obj->{"_pbl"} //= _parse_labels($obj->page_label)
l!l&&r!l&&!r
01250
MC/DC0%0/2
$obj->{"_pbl"} //= _parse_labels($obj->page_label)
$obj->{"_pbl"} _parse_labels($obj->page_label)
Truth table33%1/3
A //= B
A= $obj->{"_pbl"}B= _parse_labels($obj->page_label)
ABresult
1X1
011
000
808  
809 # pre-build pane label closures per pane index
810 125 my(@pane_top, @pane_bottom, @page_top, @page_bottom);
811 125 my($bw_l, $bw_c, $bw_r);
812 125 ▶ if ($bl || $pbl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bl or $pbl) 19 106 125
Condition100%3/3
$bl or $pbl
l!l&&r!l&&!r
154106
MC/DC100%2/2
$bl or $pbl
$bl $pbl
Truth table100%3/3
A or B
A= $blB= $pbl
ABresult
1X1
011
000
813 19 $bw_l = ansi_width($obj->get_border('left', 0));
814 19 $bw_c = ansi_width($obj->get_border('center', 0));
815 19 $bw_r = ansi_width($obj->get_border('right', 0));
816 19 my $span = $obj->{span};
817 19 for my $set ([ \@pane_top, \@page_top, qw(nw n ne) ],
818 [ \@pane_bottom, \@page_bottom, qw(sw s se) ]) {
819 38 my($pane_list, $page_list, @keys) = @$set;
820 38 ▶ if ($bl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bl) 30 8 38
821 30 my @g = map { $bl->{$_} } @keys;
822 30 ▶ if (grep { $_ } @g) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_;} @g) 17 13 30
823 17 my $fp = $bw_l;
824 17 for my $i (0 .. $obj->panes - 1) {
825 33 my($fs, $fe) = ($fp, $fp + $span);
826 153 ▶ push @$pane_list, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
827 153 my($line, $n0, $p, $name, $npanes) = @_;
828 153 $obj->_overlay_labels($line, $fs, $fe, $bw_l, $bw_r,
829 $n0 + $i + 1, $p, $name,
830 $obj->_label_more($p, $i, $npanes), @g);
831 33 };
832 33 $fp += $span + $bw_c;
833 }
834 }
835 }
836 38 ▶ if ($pbl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pbl) 8 30 38
837 8 my @g = map { $pbl->{$_} } @keys;
838 8 ▶ if (grep { $_ } @g) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_;} @g) 4 4 8
839 16 ▶ push @$page_list, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
840 16 my($line, $n0, $p, $name) = @_;
841 16 my $w = ansi_width($line);
842 16 $obj->_overlay_labels($line, 1, $w - 1, 1, 1,
843 $n0 + 1, $p, $name,
844 $obj->_label_more($p), @g);
845 4 };
846 }
847 }
848 }
849 }
850  
851 125 ▶ my $has_labels = @pane_top || @pane_bottom || @page_top || @page_bottom;
Condition88%8/9
@pane_top || @pane_bottom || @page_top || @page_bottom
l!l&&r!l&&!r
154106
@pane_top or @pane_bottom or @page_top
l!l&&r!l&&!r
150110
@pane_top or @pane_bottom
l!l&&r!l&&!r
114110
MC/DC75%3/4
@pane_top || @pane_bottom || @page_top || @page_bottom
@pane_top @pane_bottom @page_top @page_bottom
Truth table80%4/5
A or B or C || D
A= @pane_topB= @pane_bottomC= @page_topD= @page_bottom
ABCDresult
1XXX1
01XX1
001X1
00011
00000
852  
853 # pre-build border strings for 3 positions (top=0, middle=1, bottom=2)
854 125 my %border;
855 125 for my $pos (0, 1, 2) {
856 375 $border{$pos} = {
857 left => $obj->color_border('left', $pos),
858 center => $obj->color_border('center', $pos),
859 right => $obj->color_border('right', $pos),
860 };
861 }
862  
863 530 ▶ my $print_border = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
864 530 my($side, $pos, $span, $npanes, $n0, $p, $names,
865 $pane_labels, $page_labels) = @_;
866 530 ▶ return unless $bd{$side};
Branch: 1 branch
BranchTrueFalseTotal
unless $bd{$side} 200 330 530
867 330 my $bd = $border{$pos};
868 my $line = join '',
869 $bd->{left},
870 join($bd->{center},
871 404 map { $obj->color('BORDER', $bd{$side} x $_) } @$span),
872 330 $bd->{right};
873 330 ▶ if (@$pane_labels) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$pane_labels) 134 196 330
874 134 my $i = 0;
875 134 for (@{$pane_labels}[0 .. $npanes - 1]) {
876 153 ▶ $line = $_->($line, $n0, $p, $names->[$i++] // '', $npanes);
Condition50%1/2
$$names[$i++] // ""
l!l
1530
MC/DC0%0/1
$$names[$i++] // ""
$$names[$i++]
Truth table50%1/2
A
A= $$names[$i++]
Aresult
11
00
877 }
878 }
879 330 ▶ $line = $_->($line, $n0, $p, $names->[0] // '') for @$page_labels;
Condition50%1/2
$names->[0] // ""
l!l
160
MC/DC0%0/1
$names->[0] // ""
$names->[0]
Truth table50%1/2
A
A= $names->[0]
Aresult
11
00
880 330 print $line, "\n";
881 125 };
882  
883 265 ▶ sub {
Subroutine __ANON__: called CC=13 SCAR=25.7
884 265 ▶ my $opt = ref $_[0] eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 265 0 265
885 265 ▶ my @span = $opt->{span} ? @{$opt->{span}} : (($obj->{span}) x @_);
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'span'} ? : 21 244 265
886 265 ▶ my $page = $obj->current_page // 0;
Condition50%1/2
$obj->current_page // 0
l!l
2650
MC/DC0%0/1
$obj->current_page // 0
$obj->current_page
Truth table50%1/2
A
A= $obj->current_page
Aresult
11
00
887 265 my $npanes = scalar @_;
888  
889 265 ▶ my($n0, $p) = $has_labels
Branch: 1 branch
BranchTrueFalseTotal
$has_labels ? : 147 118 265
Condition50%1/2
$obj->panes // 1
l!l
1470
MC/DC0%0/1
$obj->panes // 1
$obj->panes
Truth table50%1/2
A
A= $obj->panes
Aresult
11
00
890 ? ($page * ($obj->panes // 1), $page + 1) : ();
891 265 ▶ my $names = $opt->{names} // [];
Condition50%1/2
$opt->{"names"} // []
l!l
2650
MC/DC0%0/1
$opt->{"names"} // []
$opt->{"names"}
Truth table50%1/2
A
A= $opt->{"names"}
Aresult
11
00
892  
893 265 $print_border->('top', 0, \@span, $npanes, $n0, $p, $names,
894 \@pane_top, \@page_top);
895  
896 # content rows
897 265 my $max = max map $#{$_}, @_;
898 265 for my $i (0 .. $max) {
899 my $pos = !$bd{top} && $i == 0 ? 0
900 1155 ▶ : !$bd{bottom} && $i == $max ? 2
Branch: 2 branches
BranchTrueFalseTotal
!$bd{'top'} && $i == 0 ? : 100 1055 1155
!$bd{'bottom'} && $i == $max ? : 90 965 1055
Condition100%6/6
not $bd{"top"} and $i == 0
!ll&&!rl&&r
624431100
not $bd{"bottom"} and $i == $max
!ll&&!rl&&r
62434190
MC/DC100%2/2
not $bd{"top"} and $i == 0
not $bd{"top"} $i == 0
MC/DC100%2/2
not $bd{"bottom"} and $i == $max
not $bd{"bottom"} $i == $max
Truth table100%3/3
not(A) and B
A= not $bd{"top"}B= $i == 0
ABresult
0X0
100
111
Truth table100%3/3
not(A) and B
A= not $bd{"bottom"}B= $i == $max
ABresult
0X0
100
111
901 : 1;
902 1155 my $bd = $border{$pos};
903 1155 my @span = @span;
904 my @panes = map {
905 1155 ▶ @$_ ? ansi_sprintf("%-*s", shift @span, shift @$_) : ();
Branch: 1 branch
BranchTrueFalseTotal
@$_ ? : 2295 32 2327
906 } @_;
907 1155 print $bd->{left};
908 print join $bd->{center},
909 1155 map { $obj->color('TEXT', $_) } @panes;
910 1155 print $bd->{right};
911 1155 print "\n";
912 }
913  
914 265 $print_border->('bottom', 2, \@span, $npanes, $n0, $p, $names,
915 \@pane_bottom, \@page_bottom);
916 265 $obj;
917 125 };
918 }
919  
920 281 ▶sub _numbers {
Subroutine _numbers: called CC=1 SCAR=0.0
921 281 require Getopt::EX::Numbers;
922 281 Getopt::EX::Numbers->new(min => 1, @_);
923 }
924  
925 163 ▶sub table_out {
Subroutine table_out: called CC=68 SCAR=42.5
Pod undocumented
926 163 my $obj = shift;
927 163 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 162 163
928 # A LINE SEPARATOR is not a space between columns: it breaks a cell.
929 162 my $space = qr/[^\S\x{2028}]/;
930 162 my $split = do {
931 162 ▶ if ($obj->separator eq ' ') {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->separator eq ' ') { } 11 151 162
elsif ($obj->regex_sep) { } 0 151 151
932 # /\s+/a does not work as expected, maybe perl's bug
933 11 ▶ $obj->ignore_space ? ' ' : qr/\s{1,9999}/a;
Branch: 1 branch
BranchTrueFalseTotal
$obj->ignore_space ? : 11 0 11
934 } elsif ($obj->regex_sep) {
935 0 qr($obj->{separator});
936 } else {
937 151 qr/[\Q$obj->{separator}\E]/;
938 }
939 };
940 my @lines = map {
941 # split ' ' takes a LINE SEPARATOR as a space: do as it does,
942 # without it
943 162 ▶ $split eq ' ' && /\x{2028}/
Branch: 1 branch
BranchTrueFalseTotal
$split eq ' ' && /\x{2028}/u ? : 1 455 456
Condition100%3/3
$split eq " " and /\x{2028}/u
!ll&&!rl&&r
393621
MC/DC100%2/2
$split eq " " and /\x{2028}/u
$split eq " " /\x{2028}/u
Truth table100%3/3
A and B
A= $split eq " "B= /\x{2028}/u
ABresult
0X0
100
111
944 ? [ split /$space+/, s/\A$space+//r, $obj->table_columns_limit ]
945 : [ split $split, $_, $obj->table_columns_limit ];
946 } @_;
947 162 ▶ if (my $spec = $obj->table_remove) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = $obj->table_remove) 137 25 162
948 137 my $max_cols = max map { scalar @$_ } @lines;
949 274 my %discard = map { ($_ - 1) => 1 }
950 137 map { _numbers(max => $max_cols)->parse($_)->sequence }
951 split /,/, $spec;
952 137 my @keep = grep { !$discard{$_} } 0 .. $max_cols - 1;
953 137 @$_ = @$_[@keep] for @lines;
954 }
955 162 ▶ if ($obj->table_squeeze) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->table_squeeze) 1 161 162
956 5 ▶ my @keep = grep { my $c = $_; any { length $_->[$c] } @lines }
Subroutine __ANON__: called CC=1 SCAR=0.0
957 1 0 .. max(map { $#$_ } @lines);
958 1 @$_ = @$_[@keep] for @lines;
959 }
960 #
961 # -w / --cell: fit table into width, wrapping over-wide cells
962 #
963 162 my @fixed_width;
964 162 my $tight = 0; # --table-tight: spaces the last column may lose
965 162 my @continued; # [row][col] 1 for a wrapped cell's 2nd+ line,
966 # 2 for a line after a LINE SEPARATOR
967 my @length; # [row][col] width of the cell
968 162 ▶ if (not $obj->table_align and not $obj->table_tabs
Branch: 2 branches
BranchTrueFalseTotal
if (not $obj->table_align || $obj->table_tabs and defined $obj->width || $obj->cell) { } 131 31 162
elsif (grep {/\x{2028}/u;} map({@$_;} @lines)) { } 9 22 31
Condition88%8/9
not $obj->table_align || $obj->table_tabs and defined $obj->width || $obj->cell
!ll&&!rl&&r
427131
$obj->table_align || $obj->table_tabs
l!l&&r!l&&!r
40158
defined $obj->width or $obj->cell
l!l&&r!l&&!r
1191227
MC/DC75%3/4
not $obj->table_align || $obj->table_tabs and defined $obj->width || $obj->cell
$obj->table_align $obj->table_tabs defined $obj->width $obj->cell
Truth table80%4/5
not(A || B) and C or D
A= $obj->table_alignB= $obj->table_tabsC= defined $obj->widthD= $obj->cell
ABCDresult
1XXX0
01XX0
00000
001X1
00011
969 and (defined $obj->width or $obj->cell)) {
970 131 my @cw = map { [ map { cell_width($_) } @$_ ] } @lines;
971 131 my @content = map { max @$_ } xpose @cw;
972 131 ▶ my $overhead = $obj->item_format ? ansi_width(ansi_sprintf($obj->item_format, '')) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$obj->item_format ? : 99 32 131
973 131 my $sep = ansi_width($obj->output_separator);
974 131 ▶ my $fixed = $obj->cell ? parse_cell_spec($obj->cell, \@content) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$obj->cell ? : 13 118 131
975 131 ▶ my $budget = defined $obj->width ? $obj->get_width - $sep * (@content - 1) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $obj->width ? : 119 12 131
976 # --table-tight: the spaces at the end of the item format are not
977 # counted in the last column; they are left out below when the
978 # table does not fit the width with them
979 131 ▶ if (defined $budget and $obj->table_tight and $obj->item_format =~ /%s( +)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $budget and $obj->table_tight and $obj->item_format =~ /%s( +)\z/u) 85 46 131
Condition100%6/6
defined $budget and $obj->table_tight and $obj->item_format =~ /%s( +)\z/u
!ll&&!rl&&r
212585
defined $budget and $obj->table_tight
!ll&&!rl&&r
129110
MC/DC100%3/3
defined $budget and $obj->table_tight and $obj->item_format =~ /%s( +)\z/u
defined $budget $obj->table_tight $obj->item_format =~ /%s( +)\z/u
Truth table100%4/4
A and B and C
A= defined $budgetB= $obj->table_tightC= $obj->item_format =~ /%s( +)\z/u
ABCresult
0XX0
10X0
1100
1111
980 85 $budget += $tight = length $1;
981 }
982 131 @lines = $obj->fit_table_rows(\@lines, \@cw, \@content, $budget, $overhead, $fixed, 4, \@continued, \@length);
983 131 ▶ @fixed_width = map { defined $_ ? $_ + $overhead : undef } @$fixed if $fixed;
Branch: 2 branches
BranchTrueFalseTotal
if $fixed 13 118 131
defined $_ ? : 18 7 25
984 }
985 638 elsif (grep { /\x{2028}/ } map { @$_ } @lines) {
986 # no wrapping, but a cell has lines
987 9 my @cw = map { [ map { cell_width($_) } @$_ ] } @lines;
988 9 @lines = $obj->expand_table_rows(\@lines, \@cw, [], [], \@continued, \@length);
989 }
990 162 my @blank = map { [ map { $_ eq '' } @$_ ] } @lines;
991 162 ▶ @length = map { [ map { ansi_width $_ } @$_ ] } @lines unless @length;
Branch: 1 branch
BranchTrueFalseTotal
unless @length 22 140 162
992 162 ▶ if (my $fmt = $obj->item_format) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fmt = $obj->item_format) 107 55 162
993 # A format with a single %s only adds text around the cell, so
994 # it is put by hand and the width of the text is added.
995 107 ▶ if (my($pre, $post) = $fmt =~ /\A([^%]*+)%s([^%]*+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $fmt =~ /\A([^%]*+)%s([^%]*+)\z/u) { } 107 0 107
996 107 my $add = ansi_width($pre . $post);
997 # --table-tight: the last column has a shorter format when
998 # the table is wider than the width
999 107 my($last, $cut) = (-1, 0);
1000 107 ▶ if ($tight) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tight) 85 22 107
1001 85 my @w = map { max @$_ } xpose @length;
1002 85 ▶ @w = map { max $w[$_] + $add, $fixed_width[$_] // 0 } keys @w;
Condition50%1/2
$fixed_width[$_] // 0
l!l
0353
MC/DC0%0/1
$fixed_width[$_] // 0
$fixed_width[$_]
Truth table50%1/2
A
A= $fixed_width[$_]
Aresult
11
00
1003 85 my $over = sum(@w) + ansi_width($obj->output_separator) * $#w - $obj->get_width;
1004 85 ▶ if ($over > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($over > 0) 71 14 85
1005 71 ($last, $cut) = ($#w, min($tight, $over));
1006 71 ▶ $fixed_width[$last] -= $cut if defined $fixed_width[$last];
Branch: 1 branch
BranchTrueFalseTotal
if defined $fixed_width[$last] 0 71 71
1007 }
1008 }
1009 107 my @post = ($post, substr($post, 0, length($post) - $cut));
1010 107 for my $r (keys @lines) {
1011 1210 my $line = $lines[$r];
1012 1210 for my $c (keys @$line) {
1013 5537 ▶ my $short = $c == $last ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$c == $last ? : 1079 4458 5537
1014 5537 ▶ $line->[$c] = $pre . ($line->[$c] // '') . $post[$short];
Condition50%1/2
$line->[$c] // ""
l!l
55370
MC/DC0%0/1
$line->[$c] // ""
$line->[$c]
Truth table50%1/2
A
A= $line->[$c]
Aresult
11
00
1015 5537 $length[$r][$c] += $add - $short * $cut;
1016 }
1017 }
1018 } else {
1019 0 for my $line (@lines) {
1020 0 @$line = map { ansi_sprintf($fmt, $_) } @$line;
1021 }
1022 0 @length = map { [ map { ansi_width $_ } @$_ ] } @lines;
1023 }
1024 }
1025 #
1026 # --table-wrap-mark: put the mark where a continuation line starts,
1027 # in place of leading pad as far as the mark is wide. A line which
1028 # starts after a LINE SEPARATOR is not a continuation and has none.
1029 # --table-cell-mark: same for the first line of every non-empty cell
1030 # in a column that has a wrapped cell, so that a row start can be
1031 # told from a continuation line; the first --table-head rows (a
1032 # wrapped row counting as one) are a header and get no mark.
1033 #
1034 162 my @marked; # [row][col] mark string, for alignment below
1035 42 ▶ my $put_mark = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1036 42 my($mark, $r, $c) = @_;
1037 42 my $mw = ansi_width($mark);
1038 42 $lines[$r][$c] =~ s/^\h{0,$mw}/$mark/;
1039 42 $length[$r][$c] = ansi_width($lines[$r][$c]);
1040 42 $marked[$r][$c] = $mark;
1041 162 };
1042 162 ▶ if ((my $mark = $obj->table_wrap_mark) ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $mark = $obj->table_wrap_mark) ne "") 6 156 162
1043 6 for my $r (grep { $continued[$_] } keys @continued) {
1044 9 ▶ $put_mark->($mark, $r, $_) for grep { ($continued[$r][$_] // 0) == 1 } keys @{$continued[$r]};
Condition100%2/2
$continued[$r][$_] // 0
l!l
99
MC/DC100%1/1
$continued[$r][$_] // 0
$continued[$r][$_]
Truth table100%2/2
A
A= $continued[$r][$_]
Aresult
11
00
1045 }
1046 }
1047 162 ▶ if ((my $mark = $obj->table_cell_mark) ne '' and grep { $_ } @continued) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $mark = $obj->table_cell_mark) ne "" and grep {$_;} @continued) 14 148 162
Condition100%3/3
(my $mark = $obj->table_cell_mark) ne "" and grep {$_;} @continued
!ll&&!rl&&r
146214
MC/DC100%2/2
(my $mark = $obj->table_cell_mark) ne "" and grep {$_;} @continued
(my $mark = $obj->table_cell_mark) ne "" grep {$_;} @continued
Truth table100%3/3
A and B
A= (my $mark = $obj->table_cell_mark) ne ""B= grep {$_;} @continued
ABresult
0X0
100
111
1048 14 my %wrapped;
1049 14 for my $r (grep { $continued[$_] } keys @continued) {
1050 22 $wrapped{$_}++ for grep { $continued[$r][$_] } keys @{$continued[$r]};
1051 }
1052 14 my $row = 0; # logical row number of a non-continuation line
1053 14 for my $r (grep { not $continued[$_] } keys @lines) {
1054 38 ▶ next if $row++ < $obj->table_head;
Branch: 1 branch
BranchTrueFalseTotal
if $row++ < $obj->table_head 6 32 38
1055 32 ▶ $put_mark->($mark, $r, $_) for grep { $wrapped{$_} and not $blank[$r][$_] } keys @{$lines[$r]};
Condition66%2/3
$wrapped{$_} && !$blank[$r][$_]
!ll&&!rl&&r
30034
MC/DC50%1/2
$wrapped{$_} && !$blank[$r][$_]
$wrapped{$_} !$blank[$r][$_]
Truth table66%2/3
A && not(B)
A= $wrapped{$_}B= !$blank[$r][$_]
ABresult
0X0
100
111
1056 }
1057 }
1058 162 my @max = map { max @$_ } xpose @length;
1059 162 for my $i (grep { defined $fixed_width[$_] } keys @fixed_width) {
1060 18 ▶ $max[$i] = max($max[$i] // 0, $fixed_width[$i]);
Condition50%1/2
$max[$i] // 0
l!l
180
MC/DC0%0/1
$max[$i] // 0
$max[$i]
Truth table50%1/2
A
A= $max[$i]
Aresult
11
00
1061 }
1062 162 ▶ if ($obj->table_align) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->table_align) 4 158 162
1063 4 my @tabs = map { roundup $_, $obj->column_unit, $obj->margin } @max;
1064 #
1065 # --table-tabs
1066 #
1067 4 ▶ if ($obj->table_tabs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->table_tabs) 1 3 4
1068 1 my $cu = $obj->column_unit;
1069 1 ▶ while (my($lx, $l) = each @lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @lines) 10 1 11
1070 10 ▶ while (my($fx, $f) = each @$l) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @$l) 100 10 110
1071 100 print $f;
1072 100 ▶ if ($fx == $#{$l}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fx == $#{$l;}) { } 10 90 100
1073 10 print "\n";
1074 } else {
1075 90 print "\t" x div($tabs[$fx] - $length[$lx][$fx], $cu);
1076 }
1077 }
1078 }
1079 1 return $obj;
1080 }
1081 3 @max = map { $_ - $obj->margin } @tabs;
1082 3 $obj->output_separator = ' ' x $obj->margin;
1083 }
1084 my @align = newlist(count => int @max, default => '-',
1085 [ map --$_, map {
1086 5 _numbers(max => int @max)->parse($_)->sequence
1087 } split /,/, $obj->table_right ] => '',
1088 [ map --$_, map {
1089 161 _numbers(max => int @max)->parse($_)->sequence
1090 } split /,/, $obj->table_center ] => '=');
1091 161 ▶ my @format = map { $align[$_] eq '=' ? "%-$max[$_]s" : "%$align[$_]$max[$_]s" } keys @max;
Branch: 1 branch
BranchTrueFalseTotal
$align[$_] eq '=' ? : 2 545 547
1092 161 for my $r (keys @lines) {
1093 1553 my $line = $lines[$r];
1094 1553 ▶ next unless @$line;
Branch: 1 branch
BranchTrueFalseTotal
unless @$line 0 1553 1553
1095 1553 for my $i (keys @$line) {
1096 # Pad right/center aligned cells here, keeping a mark at the
1097 # left edge of the cell rather than in front of the content.
1098 6577 ▶ next if $align[$i] eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $align[$i] eq "-" 6510 67 6577
1099 67 my $pad = $max[$i] - $length[$r][$i];
1100 67 ▶ next if $pad <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pad <= 0 34 33 67
1101 33 ▶ $pad = int($pad / 2) if $align[$i] eq '=';
Branch: 1 branch
BranchTrueFalseTotal
if $align[$i] eq "=" 8 25 33
1102 33 $line->[$i] = (' ' x $pad) . $line->[$i];
1103 33 $length[$r][$i] += $pad;
1104 33 ▶ if (my $mark = $marked[$r][$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mark = $marked[$r][$i]) 7 26 33
1105 7 $line->[$i] =~ s/^(\h+)\Q$mark\E/$mark$1/;
1106 }
1107 }
1108 1553 my @fmt = @format[keys @$line];
1109 1553 ▶ $fmt[$#fmt] = '%s' if $align[$#fmt] ne '' and !$obj->padding;
Branch: 1 branch
BranchTrueFalseTotal
if $align[$#fmt] ne "" and not $obj->padding 1434 119 1553
Condition100%3/3
$align[$#fmt] ne "" and not $obj->padding
!ll&&!rl&&r
28911434
MC/DC100%2/2
$align[$#fmt] ne "" and not $obj->padding
$align[$#fmt] ne "" not $obj->padding
Truth table100%3/3
A and not(B)
A= $align[$#fmt] ne ""B= not $obj->padding
ABresult
0X0
100
111
1110 1553 ▶ if (grep { not defined } @$line) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not defined $_;} @$line) 0 1553 1553
1111 0 my $format = join($obj->output_separator, @fmt) . "\n";
1112 0 ansi_printf $format, @$line;
1113 0 next;
1114 }
1115 # the width of every cell is known: pad it here
1116 my @out = map {
1117 1553 my $space = ' ' x ($max[$_] - $length[$r][$_]);
1118 6577 ▶ $fmt[$_] eq '%s' ? $line->[$_]
Branch: 2 branches
BranchTrueFalseTotal
$fmt[$_] eq '%s' ? : 1434 5143 6577
$align[$_] eq '' ? : 58 5085 5143
1119 : $align[$_] eq '' ? $space . $line->[$_]
1120 : $line->[$_] . $space;
1121 } keys @$line;
1122 1553 print join($obj->output_separator, @out), "\n";
1123 }
1124 161 return $obj;
1125 }
1126  
1127 297 1;
1128  
1129 __END__
↑ Summary lib/App/ansicolumn/Table.pm »