| 1 | package Term::TablePrint; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.16.0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.183'; | |||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT_OK = qw( print_table ); | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use List::Util qw( sum max ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Scalar::Util qw( looks_like_number ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Term::Choose qw( choose ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Term::Choose::Constants qw( EXTRA_W PH SGR_ES ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Term::Choose::LineFold qw( print_columns cut_to_printwidth adjust_to_printwidth line_fold ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Term::Choose::Screen qw( hide_cursor show_cursor ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Term::Choose::ValidateOptions qw( validate_options ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Term::Choose::Util qw( get_term_width insert_sep ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Term::TablePrint::ProgressBar qw(); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | if ( $^O eq 'MSWin32' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | 0 | require Win32::Console::ANSI; | |||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 33 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | croak "new: called with " . @_ . " arguments - 0 or 1 arguments expected." if @_ > 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | 0 | my ( $opt ) = @_; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | ##### | ||||||||||||||||||||||||||||||||
| 38 | #choose( [ 'Continue with ENTER' ], { prompt => "The 'min_col_width' option has been renamed to 'col_trim_threshold'." } ) if exists $opt->{min_col_width}; # 21.02.2026 | ||||||||||||||||||||||||||||||||
| 39 | #choose( [ 'Continue with ENTER' ], { prompt => "The 'max_width_exp' option has been renamed to 'expanded_max_width'." } ) if exists $opt->{max_width_exp}; # 21.02.2026 | ||||||||||||||||||||||||||||||||
| 40 | ##### | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | my $instance_defaults = _defaults(); | |||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ( defined $opt ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | croak "new: The (optional) argument is not a HASH reference." if ref $opt ne 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | 0 | validate_options( _valid_options(), $opt, 'new' ); | |||||||||||||||||||||||||||||||
| 46 | 0 | for my $key ( keys %$opt ) { | |||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $instance_defaults->{$key} = $opt->{$key} if defined $opt->{$key}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | 0 | my $self = bless $instance_defaults, $class; | |||||||||||||||||||||||||||||||
| 51 | 0 | $self->{backup_instance_defaults} = { %$instance_defaults }; | |||||||||||||||||||||||||||||||
| 52 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub _valid_options { | ||||||||||||||||||||||||||||||
|
Subroutine
_valid_options: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 57 | return { | ||||||||||||||||||||||||||||||||
| 58 | 0 | codepage_mapping => '[ 0 1 ]', | |||||||||||||||||||||||||||||||
| 59 | expanded_line_spacing => '[ 0 1 ]', | ||||||||||||||||||||||||||||||||
| 60 | hide_cursor => '[ 0 1 ]', # documentation | ||||||||||||||||||||||||||||||||
| 61 | mouse => '[ 0 1 ]', | ||||||||||||||||||||||||||||||||
| 62 | squash_spaces => '[ 0 1 ]', | ||||||||||||||||||||||||||||||||
| 63 | table_expand => '[ 0 1 ]', | ||||||||||||||||||||||||||||||||
| 64 | trunc_fract_first => '[ 0 1 ]', | ||||||||||||||||||||||||||||||||
| 65 | pad_row_edges => '[ 0 1 ]', | ||||||||||||||||||||||||||||||||
| 66 | binary_filter => '[ 0 1 2 ]', | ||||||||||||||||||||||||||||||||
| 67 | choose_columns => '[ 0 1 2 ]', | ||||||||||||||||||||||||||||||||
| 68 | color => '[ 0 1 2 ]', | ||||||||||||||||||||||||||||||||
| 69 | page => '[ 0 1 2 ]', # undocumented | ||||||||||||||||||||||||||||||||
| 70 | search => '[ 0 1 2 ]', # | ||||||||||||||||||||||||||||||||
| 71 | keep => '[ 1-9 ][ 0-9 ]*', # undocumented | ||||||||||||||||||||||||||||||||
| 72 | col_trim_threshold => '[ 0-9 ]+', | ||||||||||||||||||||||||||||||||
| 73 | max_width_exp => '[ 0-9 ]+', # now expanded_max_width # 21.02.2026 | ||||||||||||||||||||||||||||||||
| 74 | expanded_max_width => '[ 0-9 ]+', | ||||||||||||||||||||||||||||||||
| 75 | max_rows => '[ 0-9 ]+', | ||||||||||||||||||||||||||||||||
| 76 | min_col_width => '[ 0-9 ]+', # now col_trim_threshold # 21.02.2026 | ||||||||||||||||||||||||||||||||
| 77 | progress_bar => '[ 0-9 ]+', | ||||||||||||||||||||||||||||||||
| 78 | tab_width => '[ 0-9 ]+', | ||||||||||||||||||||||||||||||||
| 79 | binary_string => 'Str', ## | ||||||||||||||||||||||||||||||||
| 80 | decimal_separator => 'Str', | ||||||||||||||||||||||||||||||||
| 81 | footer => 'Str', | ||||||||||||||||||||||||||||||||
| 82 | info => 'Str', | ||||||||||||||||||||||||||||||||
| 83 | prompt => 'Str', | ||||||||||||||||||||||||||||||||
| 84 | undef => 'Str', | ||||||||||||||||||||||||||||||||
| 85 | #thsd_sep => 'Str', | ||||||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub _defaults { | ||||||||||||||||||||||||||||||
|
Subroutine
_defaults: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 91 | return { | ||||||||||||||||||||||||||||||||
| 92 | 0 | binary_filter => 0, | |||||||||||||||||||||||||||||||
| 93 | binary_string => 'BNRY', | ||||||||||||||||||||||||||||||||
| 94 | choose_columns => 0, | ||||||||||||||||||||||||||||||||
| 95 | codepage_mapping => 0, | ||||||||||||||||||||||||||||||||
| 96 | col_trim_threshold => 30, | ||||||||||||||||||||||||||||||||
| 97 | color => 0, | ||||||||||||||||||||||||||||||||
| 98 | decimal_separator => '.', | ||||||||||||||||||||||||||||||||
| 99 | expanded_line_spacing => 1, | ||||||||||||||||||||||||||||||||
| 100 | #expanded_max_width => undef, | ||||||||||||||||||||||||||||||||
| 101 | #footer => undef, | ||||||||||||||||||||||||||||||||
| 102 | hide_cursor => 1, | ||||||||||||||||||||||||||||||||
| 103 | #info => undef, | ||||||||||||||||||||||||||||||||
| 104 | #keep => undef, | ||||||||||||||||||||||||||||||||
| 105 | max_rows => 0, | ||||||||||||||||||||||||||||||||
| 106 | mouse => 0, | ||||||||||||||||||||||||||||||||
| 107 | pad_row_edges => 0, | ||||||||||||||||||||||||||||||||
| 108 | page => 2, ## | ||||||||||||||||||||||||||||||||
| 109 | progress_bar => 40000, | ||||||||||||||||||||||||||||||||
| 110 | prompt => '', | ||||||||||||||||||||||||||||||||
| 111 | search => 1, | ||||||||||||||||||||||||||||||||
| 112 | squash_spaces => 0, | ||||||||||||||||||||||||||||||||
| 113 | tab_width => 2, | ||||||||||||||||||||||||||||||||
| 114 | table_expand => 1, | ||||||||||||||||||||||||||||||||
| 115 | trunc_fract_first => 1, | ||||||||||||||||||||||||||||||||
| 116 | undef => '', | ||||||||||||||||||||||||||||||||
| 117 | thsd_sep => ',', # | ||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub __reset { | ||||||||||||||||||||||||||||||
|
Subroutine
__reset: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||
| 123 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ( $self->{hide_cursor} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 125 | 0 | print show_cursor(); | |||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ( exists $self->{backup_instance_defaults} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | 0 | my $instance_defaults = $self->{backup_instance_defaults}; | |||||||||||||||||||||||||||||||
| 129 | 0 | for my $key ( keys %$self ) { | |||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ( $key eq 'plugin' || $key eq 'backup_instance_defaults' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$key eq "plugin" or $key eq "backup_instance_defaults"
MC/DC0%0/2
$key eq "plugin" or $key eq "backup_instance_defaults"
$key eq "plugin"
$key eq "backup_instance_defaults"
Truth table0%0/3
A or B
A= $key eq "plugin"B= $key eq "backup_instance_defaults"
| |||||||||||||||||||||||||||||||||
| 131 | 0 | next; | |||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | elsif ( exists $instance_defaults->{$key} ) { | ||||||||||||||||||||||||||||||||
| 134 | 0 | $self->{$key} = $instance_defaults->{$key}; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||
| 137 | 0 | delete $self->{$key}; | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 1 | my $last_write_table = 0; | |||||||||||||||||||||||||||||||
| 145 | 1 | my $window_width_changed = 1; | |||||||||||||||||||||||||||||||
| 146 | 1 | my $enter_search_string = 2; | |||||||||||||||||||||||||||||||
| 147 | 1 | my $from_filtered_table = 3; | |||||||||||||||||||||||||||||||
| 148 | 1 | my $choose_and_print = 4; | |||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub print_table { | ||||||||||||||||||||||||||||||
|
Subroutine
print_table: not called CC=27 SCAR=66.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ( ref $_[0] ne __PACKAGE__ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | 0 | my $ob = __PACKAGE__->new(); | |||||||||||||||||||||||||||||||
| 154 | 0 | delete $ob->{backup_instance_defaults}; | |||||||||||||||||||||||||||||||
| 155 | 0 | return $ob->print_table( @_ ); | |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 158 | 0 | my ( $tbl_orig, $opt ) = @_; | |||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | croak "print_table: called with " . @_ . " arguments - 1 or 2 arguments expected." if @_ < 1 || @_ > 2; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ < 1 or @_ > 2
MC/DC0%0/2
@_ < 1 or @_ > 2
@_ < 1
@_ > 2
Truth table0%0/3
A or B
A= @_ < 1B= @_ > 2
| |||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | croak "print_table: requires an ARRAY reference as its first argument." if ref $tbl_orig ne 'ARRAY'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if ( defined $opt ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | croak "print_table: the (optional) second argument is not a HASH reference." if ref $opt ne 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | ##### | ||||||||||||||||||||||||||||||||
| 165 | #choose( [ 'Continue with ENTER' ], { prompt => "The 'min_col_width' option has been renamed to 'col_trim_threshold'." } ) if exists $opt->{min_col_width}; # 21.02.2026 | ||||||||||||||||||||||||||||||||
| 166 | #choose( [ 'Continue with ENTER' ], { prompt => "The 'max_width_exp' option has been renamed to 'expanded_max_width'." } ) if exists $opt->{max_width_exp}; # 21.02.2026 | ||||||||||||||||||||||||||||||||
| 167 | ##### | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | 0 | validate_options( _valid_options(), $opt, 'print_table' ); | |||||||||||||||||||||||||||||||
| 170 | 0 | for my $key ( keys %$opt ) { | |||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $self->{$key} = $opt->{$key} if defined $opt->{$key}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||
| 174 | 0 | local $| = 1; | |||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | local $SIG{INT} = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 176 | 0 | $self->__reset(); | |||||||||||||||||||||||||||||||
| 177 | 0 | print "\n"; | |||||||||||||||||||||||||||||||
| 178 | 0 | exit; | |||||||||||||||||||||||||||||||
| 179 | 0 | }; | |||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if ( print_columns( $self->{decimal_separator} ) != 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 181 | 0 | $self->{decimal_separator} = '.'; | |||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ( $self->{decimal_separator} ne '.' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 184 | 0 | $self->{thsd_sep} = '_'; | |||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ( $self->{hide_cursor} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 187 | 0 | print hide_cursor(); | |||||||||||||||||||||||||||||||
| 188 | # 'choose' functions: Deactivate 'hide_cursor', because if 'hide_cursor' is | ||||||||||||||||||||||||||||||||
| 189 | # activated (default), 'choose' activates the cursor before returning. | ||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if ( ! @$tbl_orig || ! @{$tbl_orig->[0]} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$tbl_orig and @{$tbl_orig->[0];}
MC/DC0%0/2
@$tbl_orig and @{$tbl_orig->[0];}
@$tbl_orig
@{$tbl_orig->[0];}
Truth table0%0/3
A and B
A= @$tbl_origB= @{$tbl_orig->[0];}
| |||||||||||||||||||||||||||||||||
| 192 | 0 | my $message; | |||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ( ! @$tbl_orig ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 194 | 0 | $message = "'print_table': Empty table without header row!"; | |||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||
| 196 | else { | ||||||||||||||||||||||||||||||||
| 197 | 0 | $message = "'print_table': No columns!"; | |||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||
| 199 | # Choose | ||||||||||||||||||||||||||||||||
| 200 | 0 | choose( | |||||||||||||||||||||||||||||||
| 201 | [ 'Close with ENTER' ], | ||||||||||||||||||||||||||||||||
| 202 | { prompt => $message, hide_cursor => 0 } | ||||||||||||||||||||||||||||||||
| 203 | ); | ||||||||||||||||||||||||||||||||
| 204 | 0 | $self->__reset(); | |||||||||||||||||||||||||||||||
| 205 | 0 | return; | |||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | 0 | $self->{_last_index} = $#$tbl_orig; ## | |||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ( $self->{max_rows} && $self->{_last_index} > $self->{max_rows} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"max_rows"} and $self->{"_last_index"} > $self->{"max_rows"}
MC/DC0%0/2
$self->{"max_rows"} and $self->{"_last_index"} > $self->{"max_rows"}
$self->{"max_rows"}
$self->{"_last_index"} > $self->{"max_rows"}
Truth table0%0/3
A and B
A= $self->{"max_rows"}B= $self->{"_last_index"} > $self->{"max_rows"}
| |||||||||||||||||||||||||||||||||
| 209 | 0 | $self->{_info_row} = sprintf( 'Limited to %s rows', insert_sep( $self->{max_rows}, $self->{thsd_sep} ) ); | |||||||||||||||||||||||||||||||
| 210 | 0 | $self->{_info_row} .= sprintf( ' (total %s)', insert_sep( $self->{_last_index}, $self->{thsd_sep} ) ); | |||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | $self->{_info_row} = ' ' . $self->{_info_row} if $self->{pad_row_edges}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 212 | 0 | $self->{_last_index} = $self->{max_rows}; | |||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||
| 214 | 0 | $self->{_search_regex} = ''; | |||||||||||||||||||||||||||||||
| 215 | 0 | $self->{_idx_search_matches} = []; | |||||||||||||||||||||||||||||||
| 216 | 0 | my $width = {}; | |||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $width->{edge} = $self->{pad_row_edges} ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 218 | 0 | my ( $tbl_print, $header_rows ) = $self->__get_data( $tbl_orig, $width ); | |||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ( ! defined $tbl_print ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 220 | 0 | $self->__reset(); | |||||||||||||||||||||||||||||||
| 221 | 0 | return; | |||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | 0 | WRITE_TABLE: while ( 1 ) { | |||||||||||||||||||||||||||||||
| 225 | 0 | my $next = $self->__write_table( $tbl_orig, $tbl_print, $header_rows, $width ); | |||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ( ! defined $next ) { | ||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||
| 227 | 0 | die; | |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | elsif ( $next == $last_write_table ) { | ||||||||||||||||||||||||||||||||
| 230 | 0 | last WRITE_TABLE; | |||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||
| 232 | ▶ | elsif ( $next == $window_width_changed || $next == $choose_and_print ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$next == $window_width_changed or $next == $choose_and_print
MC/DC0%0/2
$next == $window_width_changed or $next == $choose_and_print
$next == $window_width_changed
$next == $choose_and_print
Truth table0%0/3
A or B
A= $next == $window_width_changedB= $next == $choose_and_print
| |||||||||||||||||||||||||||||||||
| 233 | 0 | ( $tbl_print, $header_rows ) = $self->__get_data( $tbl_orig, $width, $next ); | |||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if ( ! defined $tbl_print ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 235 | 0 | $self->__reset(); | |||||||||||||||||||||||||||||||
| 236 | 0 | return; | |||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||
| 238 | 0 | next WRITE_TABLE; | |||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||
| 240 | elsif ( $next == $enter_search_string ) { | ||||||||||||||||||||||||||||||||
| 241 | 0 | $self->__search( $tbl_orig ); | |||||||||||||||||||||||||||||||
| 242 | 0 | next WRITE_TABLE; | |||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||
| 244 | elsif ( $next == $from_filtered_table ) { | ||||||||||||||||||||||||||||||||
| 245 | 0 | $self->__reset_search(); | |||||||||||||||||||||||||||||||
| 246 | 0 | next WRITE_TABLE; | |||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||
| 249 | 0 | $self->__reset(); | |||||||||||||||||||||||||||||||
| 250 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub __used_columns { | ||||||||||||||||||||||||||||||
|
Subroutine
__used_columns: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||
| 255 | 0 | my ( $self, $tbl_orig, $width, $next ) = @_; | |||||||||||||||||||||||||||||||
| 256 | my $tcu = Term::Choose::Util->new( | ||||||||||||||||||||||||||||||||
| 257 | { index => 1, all_by_default => 1, keep_chosen => 1, cs_begin => "\n", confirm => '-OK-', back => ' << ', | ||||||||||||||||||||||||||||||||
| 258 | color => $self->{color}, footer => $self->{footer}, mouse => $self->{mouse} } # pad_row_edges | ||||||||||||||||||||||||||||||||
| 259 | 0 | ); | |||||||||||||||||||||||||||||||
| 260 | 0 | my $cols; | |||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if ( defined $next && $next == $window_width_changed ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $next and $next == $window_width_changed
MC/DC0%0/2
defined $next and $next == $window_width_changed
defined $next
$next == $window_width_changed
Truth table0%0/3
A and B
A= defined $nextB= $next == $window_width_changed
| |||||||||||||||||||||||||||||||||
| 262 | 0 | $cols = [ @{$self->{_desired_cols_tbl_orig}} ]; | |||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||
| 264 | elsif ( $self->{choose_columns} == 1 ) { | ||||||||||||||||||||||||||||||||
| 265 | # Choose | ||||||||||||||||||||||||||||||||
| 266 | 0 | $cols = $tcu->choose_a_subset( $tbl_orig->[0], { cs_label => 'Chosen columns:' } ); | |||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ( ! defined $cols ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 268 | 0 | return; | |||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||
| 271 | else { | ||||||||||||||||||||||||||||||||
| 272 | 0 | $cols = [ 0 .. $#{$tbl_orig->[0]} ]; | |||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | my $min_col_w_th = $self->{choose_columns} ? 3 : 2; # min_col_width_treshold | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 275 | 0 | my $desired_cols; | |||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | while ( ( $width->{tab} + $min_col_w_th ) * $#$cols + $min_col_w_th + $width->{edge} * 2 > $width->{term} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 278 | 0 | $width->{tab} -= 2; | |||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ( $width->{tab} < 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if ( $self->{choose_columns} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if ( ! $desired_cols ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 282 | 0 | $desired_cols = [ @$cols ]; | |||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||
| 284 | 0 | $width->{tab} = $self->{tab_width}; | |||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | if ( ! ( $self->{tab_width} % 2 ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 286 | 0 | ++$width->{tab}; | |||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||
| 288 | 0 | my $avail_w = $width->{term} - ( $width->{edge} * 2 + $min_col_w_th ); | |||||||||||||||||||||||||||||||
| 289 | 0 | my $max_cols = 1 + int( $avail_w / ( 1 + $min_col_w_th ) ); | |||||||||||||||||||||||||||||||
| 290 | 0 | my $cs_label = "Current window width only supports $max_cols columns."; | |||||||||||||||||||||||||||||||
| 291 | 0 | $cs_label .= "\nPlease reduce your selection or widen the terminal:"; | |||||||||||||||||||||||||||||||
| 292 | # Choose | ||||||||||||||||||||||||||||||||
| 293 | 0 | my $new_cols = $tcu->choose_a_subset( [ @{$tbl_orig->[0]}[@$cols] ], { cs_label => $cs_label } ); | |||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ( ! defined $new_cols ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 295 | 0 | return; | |||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||
| 297 | 0 | $width->{term} = get_term_width() + EXTRA_W; | |||||||||||||||||||||||||||||||
| 298 | 0 | $cols = [ @{$cols}[@$new_cols] ]; | |||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||
| 300 | else { | ||||||||||||||||||||||||||||||||
| 301 | 0 | my $info = 'Too many columns; the terminal window is not wide enough.'; | |||||||||||||||||||||||||||||||
| 302 | 0 | my $prompt = 'Close with ENTER.'; | |||||||||||||||||||||||||||||||
| 303 | # Choose | ||||||||||||||||||||||||||||||||
| 304 | choose( | ||||||||||||||||||||||||||||||||
| 305 | $tbl_orig->[0], | ||||||||||||||||||||||||||||||||
| 306 | # [ @{$tbl_orig->[0]}[@$cols] ], | ||||||||||||||||||||||||||||||||
| 307 | { info => $info, prompt => $prompt, clear_screen => 1, mouse => $self->{mouse}, hide_cursor => 0, | ||||||||||||||||||||||||||||||||
| 308 | search => $self->{search}, footer => $self->{footer}, color => $self->{color}, | ||||||||||||||||||||||||||||||||
| 309 | codepage_mapping => $self->{codepage_mapping} } | ||||||||||||||||||||||||||||||||
| 310 | 0 | ); | |||||||||||||||||||||||||||||||
| 311 | 0 | return; | |||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if ( ! $desired_cols ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 316 | 0 | $desired_cols = $cols; | |||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||
| 318 | 0 | return $desired_cols, $cols; | |||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | sub __get_data { | ||||||||||||||||||||||||||||||
|
Subroutine
__get_data: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||
| 323 | 0 | my ( $self, $tbl_orig, $width, $next ) = @_; | |||||||||||||||||||||||||||||||
| 324 | 0 | $width->{term}= get_term_width() + EXTRA_W; | |||||||||||||||||||||||||||||||
| 325 | 0 | $width->{tab} = $self->{tab_width}; | |||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if ( ! ( $self->{tab_width} % 2 ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 327 | 0 | ++$width->{tab}; # include the `|` | |||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | 0 | my ( $desired_cols, $possible_cols ) = $self->__used_columns( $tbl_orig, $width, $next ); | |||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if ( ! defined $desired_cols ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 331 | 0 | return; | |||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||
| 333 | 0 | $self->{_used_cols_tbl_orig} = $possible_cols; | |||||||||||||||||||||||||||||||
| 334 | 0 | $self->{_desired_cols_tbl_orig} = $desired_cols; | |||||||||||||||||||||||||||||||
| 335 | 0 | my $items_count = $self->{_last_index} * @{$tbl_orig->[0]}; ## | |||||||||||||||||||||||||||||||
| 336 | my $progress = Term::TablePrint::ProgressBar->new( { | ||||||||||||||||||||||||||||||||
| 337 | total => $self->{_last_index} * 3 + 2, # + 2: 2 out of 3 loops include the header. | ||||||||||||||||||||||||||||||||
| 338 | 0 | show_progress_bar => $self->{progress_bar} < $items_count, | |||||||||||||||||||||||||||||||
| 339 | } ); | ||||||||||||||||||||||||||||||||
| 340 | 0 | my $tbl_copy = $self->__copy_table( $tbl_orig, $progress ); | |||||||||||||||||||||||||||||||
| 341 | 0 | $self->__calc_col_width( $tbl_copy, $width, $progress ); | |||||||||||||||||||||||||||||||
| 342 | 0 | $self->__calc_avail_col_width( $tbl_copy, $width ); | |||||||||||||||||||||||||||||||
| 343 | 0 | $width->{table} = sum( @{$width->{cols_calc}}, $width->{tab} * $#{$width->{cols_calc}}, 2 * $width->{edge} ); | |||||||||||||||||||||||||||||||
| 344 | 0 | my $tbl_print = $self->__cols_to_string( $tbl_orig, $tbl_copy, $width, $progress ); | |||||||||||||||||||||||||||||||
| 345 | 0 | my @tmp_header_rows; | |||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | if ( length $self->{prompt} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 347 | 0 | push @tmp_header_rows, $self->{prompt}; | |||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ( length $self->{info} || length $self->{prompt} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $self->{"info"} or length $self->{"prompt"}
MC/DC0%0/2
length $self->{"info"} or length $self->{"prompt"}
length $self->{"info"}
length $self->{"prompt"}
Truth table0%0/3
A or B
A= length $self->{"info"}B= length $self->{"prompt"}
| |||||||||||||||||||||||||||||||||
| 350 | 0 | push @tmp_header_rows, $self->__header_sep( $width ); | |||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||
| 352 | 0 | my $col_names = shift @{$tbl_print}; | |||||||||||||||||||||||||||||||
| 353 | 0 | push @tmp_header_rows, $col_names, $self->__header_sep( $width ); | |||||||||||||||||||||||||||||||
| 354 | 0 | my $header_rows = join "\n", @tmp_header_rows; | |||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if ( $self->{_info_row} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if ( print_columns( $self->{_info_row} ) > $width->{table} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 357 | 0 | push @{$tbl_print}, cut_to_printwidth( $self->{_info_row}, $width->{table} - 3 ) . '...'; | |||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||
| 359 | else { | ||||||||||||||||||||||||||||||||
| 360 | 0 | push @{$tbl_print}, $self->{_info_row}; | |||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||
| 363 | 0 | return $tbl_print, $header_rows; | |||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | sub __write_table { | ||||||||||||||||||||||||||||||
|
Subroutine
__write_table: not called CC=24 SCAR=64.0
| |||||||||||||||||||||||||||||||||
| 368 | 0 | my ( $self, $tbl_orig, $tbl_print, $header_rows, $width ) = @_; | |||||||||||||||||||||||||||||||
| 369 | 0 | my @idxs_tbl_print; | |||||||||||||||||||||||||||||||
| 370 | my $return; | ||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | if ( $self->{_search_regex} ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 372 | 0 | @idxs_tbl_print = map { $_ - 1 } @{$self->{_idx_search_matches}}; # because of the removed tbl_print header | |||||||||||||||||||||||||||||||
| 373 | 0 | $return = $from_filtered_table; | |||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||
| 375 | elsif ( $self->{choose_columns} == 1 ) { | ||||||||||||||||||||||||||||||||
| 376 | 0 | $return = $choose_and_print; | |||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||
| 378 | else { | ||||||||||||||||||||||||||||||||
| 379 | 0 | $return = $last_write_table; | |||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||
| 381 | 0 | my $footer; | |||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | if ( $self->{footer} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 383 | 0 | $footer = $self->{footer}; | |||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if ( $self->{_search_regex} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 385 | 0 | $footer .= "[$self->{_search_regex}]"; | |||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | my $old_row = exists $ENV{TC_POS_AT_SEARCH} && ! $self->{_search_regex} ? delete( $ENV{TC_POS_AT_SEARCH} ) : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $ENV{"TC_POS_AT_SEARCH"} and not $self->{"_search_regex"}
MC/DC0%0/2
exists $ENV{"TC_POS_AT_SEARCH"} and not $self->{"_search_regex"}
exists $ENV{"TC_POS_AT_SEARCH"}
not $self->{"_search_regex"}
Truth table0%0/3
A and not(B)
A= exists $ENV{"TC_POS_AT_SEARCH"}B= not $self->{"_search_regex"}
| |||||||||||||||||||||||||||||||||
| 389 | 0 | my $auto_jumped_to_row_0 = 0; | |||||||||||||||||||||||||||||||
| 390 | 0 | my $row_was_expanded = 0; | |||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||
| 392 | 0 | while ( 1 ) { | |||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ( $width->{term} != get_term_width() + EXTRA_W ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 394 | 0 | return $window_width_changed; | |||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | if ( ! @{$tbl_print} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 397 | 0 | push @{$tbl_print}, ''; # so that going back requires always the same amount of keystrokes | |||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||
| 399 | 0 | $ENV{TC_RESET_AUTO_UP} = 0; | |||||||||||||||||||||||||||||||
| 400 | # Choose | ||||||||||||||||||||||||||||||||
| 401 | my $row = choose( | ||||||||||||||||||||||||||||||||
| 402 | 0 | @idxs_tbl_print ? [ @{$tbl_print}[@idxs_tbl_print] ] | |||||||||||||||||||||||||||||||
| 403 | : $tbl_print, | ||||||||||||||||||||||||||||||||
| 404 | { info => $self->{info}, prompt => $header_rows, index => 1, default => $old_row, ll => $width->{table}, layout => 2, | ||||||||||||||||||||||||||||||||
| 405 | clear_screen => 1, mouse => $self->{mouse}, hide_cursor => 0, footer => $footer, color => $self->{color}, | ||||||||||||||||||||||||||||||||
| 406 | codepage_mapping => $self->{codepage_mapping}, search => $self->{search}, keep => $self->{keep}, | ||||||||||||||||||||||||||||||||
| 407 | page => $self->{page} } | ||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | if ( ! defined $row ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 410 | 0 | return $return; | |||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||
| 412 | elsif ( $row < 0 ) { | ||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if ( $row == -1 ) { # with option `ll` set and changed window width `choose` returns -1; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 414 | 0 | return $window_width_changed; | |||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||
| 416 | elsif ( $row == -13 ) { # with option `ll` set `choose` returns -13 if `Ctrl-F` was pressed | ||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | if ( $self->{_search_regex} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 418 | 0 | $self->__reset_search(); | |||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||
| 420 | 0 | return $enter_search_string; | |||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||
| 422 | else { | ||||||||||||||||||||||||||||||||
| 423 | 0 | return $last_write_table; | |||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | if ( ! $self->{table_expand} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | return $return if $row == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 428 | 0 | next; | |||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | if ( $ENV{TC_RESET_AUTO_UP} ) { # true if any key other than Return/Enter was pressed | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 431 | 0 | $auto_jumped_to_row_0 = 0; | |||||||||||||||||||||||||||||||
| 432 | 0 | $row_was_expanded = 0; | |||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||
| 434 | #if ( $old_row == $row ) { | ||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if ( $row_was_expanded ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if ( $row == 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 437 | 0 | return $return; | |||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||
| 439 | 0 | $old_row = 0; | |||||||||||||||||||||||||||||||
| 440 | 0 | $auto_jumped_to_row_0 = 1; | |||||||||||||||||||||||||||||||
| 441 | 0 | $row_was_expanded = 0; | |||||||||||||||||||||||||||||||
| 442 | 0 | next; | |||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ( $auto_jumped_to_row_0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 445 | 0 | return $return; | |||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||
| 447 | #} | ||||||||||||||||||||||||||||||||
| 448 | 0 | $old_row = $row; | |||||||||||||||||||||||||||||||
| 449 | 0 | $row_was_expanded = 1; | |||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | if ( $self->{_info_row} && $row == $#{$tbl_print} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_info_row"} and $row == $#{$tbl_print;}
MC/DC0%0/2
$self->{"_info_row"} and $row == $#{$tbl_print;}
$self->{"_info_row"}
$row == $#{$tbl_print;}
Truth table0%0/3
A and B
A= $self->{"_info_row"}B= $row == $#{$tbl_print;}
| |||||||||||||||||||||||||||||||||
| 451 | # Choose | ||||||||||||||||||||||||||||||||
| 452 | choose( | ||||||||||||||||||||||||||||||||
| 453 | [ 'Close' ], | ||||||||||||||||||||||||||||||||
| 454 | 0 | { prompt => $self->{_info_row}, clear_screen => 1, mouse => $self->{mouse}, hide_cursor => 0 } | |||||||||||||||||||||||||||||||
| 455 | ); | ||||||||||||||||||||||||||||||||
| 456 | 0 | next; | |||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||
| 458 | 0 | my $orig_row; | |||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | if ( @{$self->{_idx_search_matches}} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 460 | 0 | $orig_row = $self->{_idx_search_matches}[$row]; | |||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||
| 462 | else { | ||||||||||||||||||||||||||||||||
| 463 | 0 | $orig_row = $row + 1; # because $tbl_print has no header row while $tbl_orig has a header row | |||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||
| 465 | 0 | $self->__print_single_row( $tbl_orig, $orig_row, $width, $footer ); | |||||||||||||||||||||||||||||||
| 466 | 0 | delete $ENV{TC_RESET_AUTO_UP}; | |||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | sub __copy_table { | ||||||||||||||||||||||||||||||
|
Subroutine
__copy_table: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||
| 472 | 0 | my ( $self, $tbl_orig, $progress ) = @_; | |||||||||||||||||||||||||||||||
| 473 | 0 | my $tbl_copy = []; | |||||||||||||||||||||||||||||||
| 474 | 0 | $progress->set_progress_bar(); | |||||||||||||||||||||||||||||||
| 475 | 0 | my $str; | |||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||
| 477 | 0 | ROW: for my $i ( 0 .. $self->{_last_index} ) { | |||||||||||||||||||||||||||||||
| 478 | 0 | my $tmp_row = []; | |||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||
| 480 | 0 | COL: for my $j ( @{$self->{_used_cols_tbl_orig}} ) { | |||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | $str = $tbl_orig->[$i][$j] // $self->{undef}; # this is where the copying happens | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$tbl_orig->[$i][$j] // $self->{"undef"}
MC/DC0%0/2
$tbl_orig->[$i][$j] // $self->{"undef"}
$tbl_orig->[$i][$j]
$self->{"undef"}
Truth table0%0/3
A // B
A= $tbl_orig->[$i][$j]B= $self->{"undef"}
| |||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | $str = _handle_reference( $str ) if ref $str; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | if ( $self->{color} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 484 | 0 | $str =~ s/${\PH}//g; | |||||||||||||||||||||||||||||||
| 485 | 0 | $str =~ s/${\SGR_ES}/${\PH}/g; | |||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | if ( $self->{binary_filter} && substr( $str, 0, 100 ) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"binary_filter"} and substr($str, 0, 100) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/u
MC/DC0%0/2
$self->{"binary_filter"} and substr($str, 0, 100) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/u
$self->{"binary_filter"}
substr($str, 0, 100) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/u
Truth table0%0/3
A and B
A= $self->{"binary_filter"}B= substr($str, 0, 100) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/u
| |||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if ( $self->{binary_filter} == 2 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | push @$tmp_row, sprintf( '%*v02X', ' ', $tbl_orig->[$i][$j] // $self->{undef} ); | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$tbl_orig->[$i][$j] // $self->{"undef"}
MC/DC0%0/2
$tbl_orig->[$i][$j] // $self->{"undef"}
$tbl_orig->[$i][$j]
$self->{"undef"}
Truth table0%0/3
A // B
A= $tbl_orig->[$i][$j]B= $self->{"undef"}
| |||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||
| 491 | else { | ||||||||||||||||||||||||||||||||
| 492 | 0 | push @$tmp_row, $self->{binary_string}; | |||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||
| 494 | 0 | next COL; | |||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | if ( $str =~ /[\p{Cc}\p{Noncharacter_Code_Point}\p{Cs}]/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 497 | 0 | $str =~ s/\t/ /g; | |||||||||||||||||||||||||||||||
| 498 | 0 | $str =~ s/\v+/\ \ /g; | |||||||||||||||||||||||||||||||
| 499 | 0 | $str =~ s/[\p{Cc}\p{Noncharacter_Code_Point}\p{Cs}]//g; | |||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | if ( $self->{squash_spaces} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 502 | 0 | $str =~ s/^\p{Space}+//; | |||||||||||||||||||||||||||||||
| 503 | 0 | $str =~ s/\p{Space}+\z//; | |||||||||||||||||||||||||||||||
| 504 | 0 | $str =~ s/\p{Space}+/ /g; | |||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||
| 506 | 0 | push @$tmp_row, $str; | |||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||
| 508 | 0 | push @$tbl_copy, $tmp_row; | |||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | if ( $progress->{show_progress_bar} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | if ( ++$progress->{count} > $progress->{next_update} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 511 | 0 | $progress->update_progress_bar(); | |||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||
| 515 | 0 | return $tbl_copy | |||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | sub __calc_col_width { | ||||||||||||||||||||||||||||||
|
Subroutine
__calc_col_width: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||||||
| 520 | 0 | my ( $self, $tbl_copy, $width, $progress ) = @_; | |||||||||||||||||||||||||||||||
| 521 | 0 | $progress->set_progress_bar(); # | |||||||||||||||||||||||||||||||
| 522 | 0 | my $ds = $self->{decimal_separator}; | |||||||||||||||||||||||||||||||
| 523 | 0 | my $regex_int_fract = "^([^${ds}Ee]*)(\Q${ds}\E[0-9]+)?\\z"; | |||||||||||||||||||||||||||||||
| 524 | 0 | my @col_idx = ( 0 .. $#{$tbl_copy->[0]} ); | |||||||||||||||||||||||||||||||
| 525 | 0 | my $col_count = @col_idx; | |||||||||||||||||||||||||||||||
| 526 | 0 | $width->{col_names} = []; | |||||||||||||||||||||||||||||||
| 527 | 0 | $width->{cols} = [ ( 1 ) x $col_count ]; | |||||||||||||||||||||||||||||||
| 528 | 0 | $width->{int} = [ ( 0 ) x $col_count ]; | |||||||||||||||||||||||||||||||
| 529 | 0 | $width->{fract} = [ ( 0 ) x $col_count ]; | |||||||||||||||||||||||||||||||
| 530 | 0 | for my $col ( @col_idx ) { | |||||||||||||||||||||||||||||||
| 531 | 0 | $width->{col_names}[$col] = print_columns( $tbl_copy->[0][$col] ); | |||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||
| 534 | 0 | for my $row ( 1 .. $#$tbl_copy ) { | |||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||
| 536 | 0 | for my $col ( @col_idx ) { | |||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | if ( ! length $tbl_copy->[$row][$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 538 | # nothing to do | ||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||
| 540 | elsif ( looks_like_number $tbl_copy->[$row][$col] ) { | ||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | if ( $tbl_copy->[$row][$col] =~ /$regex_int_fract/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | if ( ( length $1 // 0 ) > $width->{int}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
length $1 // 0
MC/DC0%0/1
length $1 // 0
length $1
Truth table0%0/2
A
A= length $1
| |||||||||||||||||||||||||||||||||
| 543 | 0 | $width->{int}[$col] = length $1; | |||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | if ( ( length $2 // 0 ) > $width->{fract}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
length $2 // 0
MC/DC0%0/1
length $2 // 0
length $2
Truth table0%0/2
A
A= length $2
| |||||||||||||||||||||||||||||||||
| 546 | 0 | $width->{fract}[$col] = length $2; | |||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||
| 549 | else { | ||||||||||||||||||||||||||||||||
| 550 | # scientific notation | ||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | if ( length $tbl_copy->[$row][$col] > $width->{cols}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 552 | 0 | $width->{cols}[$col] = length $tbl_copy->[$row][$col]; | |||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||
| 556 | else { | ||||||||||||||||||||||||||||||||
| 557 | 0 | my $str_w = print_columns( $tbl_copy->[$row][$col] ); | |||||||||||||||||||||||||||||||
| 558 | 0 | ▶ | if ( $str_w > $width->{cols}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 559 | 0 | $width->{cols}[$col] = $str_w; | |||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | if ( $progress->{show_progress_bar} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | if ( ++$progress->{count} > $progress->{next_update} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 565 | 0 | $progress->update_progress_bar(); | |||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||
| 570 | 0 | for my $col ( @col_idx ) { | |||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | if ( $width->{int}[$col] + $width->{fract}[$col] > $width->{cols}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 572 | 0 | $width->{cols}[$col] = $width->{int}[$col] + $width->{fract}[$col]; | |||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||
| 575 | 0 | return; | |||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | sub __calc_avail_col_width { | ||||||||||||||||||||||||||||||
|
Subroutine
__calc_avail_col_width: not called CC=29 SCAR=67.7
| |||||||||||||||||||||||||||||||||
| 580 | 0 | my ( $self, $tbl_copy, $width ) = @_; | |||||||||||||||||||||||||||||||
| 581 | 0 | $width->{cols_calc} = [ @{$width->{cols}} ]; | |||||||||||||||||||||||||||||||
| 582 | 0 | $width->{fract_calc} = [ @{$width->{fract}} ]; | |||||||||||||||||||||||||||||||
| 583 | 0 | my $avail_w = $width->{term} - ( $width->{tab} * $#{$width->{cols_calc}} + 2 * $width->{edge} ); | |||||||||||||||||||||||||||||||
| 584 | 0 | my $sum = sum( @{$width->{cols_calc}} ); | |||||||||||||||||||||||||||||||
| 585 | 0 | my @col_idx = ( 0 .. $#{$width->{cols_calc}} ); | |||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | if ( $sum < $avail_w ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||
| 588 | 0 | HEAD: while ( 1 ) { | |||||||||||||||||||||||||||||||
| 589 | 0 | my $prev_sum = $sum; | |||||||||||||||||||||||||||||||
| 590 | 0 | for my $col ( @col_idx ) { | |||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | if ( $width->{col_names}[$col] > $width->{cols_calc}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 592 | 0 | ++$width->{cols_calc}[$col]; | |||||||||||||||||||||||||||||||
| 593 | 0 | ++$sum; | |||||||||||||||||||||||||||||||
| 594 | 0 | ▶ | if ( $sum == $avail_w ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 595 | 0 | last HEAD; | |||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | if ( $sum == $prev_sum ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 600 | 0 | last HEAD; | |||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||
| 604 | elsif ( $sum > $avail_w ) { | ||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | if ( $self->{trunc_fract_first} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||
| 607 | 0 | TRUNC_FRACT: while ( 1 ) { | |||||||||||||||||||||||||||||||
| 608 | 0 | my $prev_sum = $sum; | |||||||||||||||||||||||||||||||
| 609 | 0 | for my $col ( @col_idx ) { | |||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | if ( $width->{fract_calc}[$col] && $width->{fract_calc}[$col] > 3 # 3 == 1 decimal separator + 2 decimal places | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$width->{"fract_calc"}[$col] and $width->{"fract_calc"}[$col] > 3
MC/DC0%0/2
$width->{"fract_calc"}[$col] and $width->{"fract_calc"}[$col] > 3
$width->{"fract_calc"}[$col]
$width->{"fract_calc"}[$col] > 3
Truth table0%0/3
A and B
A= $width->{"fract_calc"}[$col]B= $width->{"fract_calc"}[$col] > 3
| |||||||||||||||||||||||||||||||||
| 611 | #&& $width->{int}[$col] + $width->{fract_calc}[$col] == $width->{cols_calc}[$col] # | ||||||||||||||||||||||||||||||||
| 612 | ## the column width could be larger than width int + width fract_calc, if the column contains non-digit strings | ||||||||||||||||||||||||||||||||
| 613 | ) { | ||||||||||||||||||||||||||||||||
| 614 | 0 | --$width->{fract_calc}[$col]; | |||||||||||||||||||||||||||||||
| 615 | 0 | --$width->{cols_calc}[$col]; | |||||||||||||||||||||||||||||||
| 616 | 0 | --$sum; | |||||||||||||||||||||||||||||||
| 617 | 0 | ▶ | if ( $sum == $avail_w ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 618 | 0 | last TRUNC_FRACT; | |||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | if ( $sum == $prev_sum ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 623 | 0 | last TRUNC_FRACT; | |||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||
| 627 | 0 | ▶ | my $min_col_width = $self->{col_trim_threshold} < 2 ? 2 : $self->{col_trim_threshold}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 628 | 0 | my $percent = 4; | |||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | TRUNC_COLS: while ( $sum > $avail_w ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 631 | 0 | ++$percent; | |||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||
| 633 | 0 | for my $col ( @col_idx ) { | |||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | if ( $width->{cols_calc}[$col] > $min_col_width ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 635 | 0 | my $reduced_col_w = _minus_x_percent( $width->{cols_calc}[$col], $percent ); | |||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | if ( $reduced_col_w < $min_col_width ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 637 | 0 | $reduced_col_w = $min_col_width; | |||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | if ( $width->{fract_calc}[$col] > 2 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 640 | 0 | $width->{fract_calc}[$col] -= $width->{cols_calc}[$col] - $reduced_col_w; | |||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | if ( $width->{fract_calc}[$col] < 2 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 642 | 0 | $width->{fract_calc}[$col] = 2; | |||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||
| 645 | #if ( $width->{fract_calc}[$col] > 0 ) { | ||||||||||||||||||||||||||||||||
| 646 | # $width->{fract_calc}[$col] -= $width->{cols_calc}[$col] - $reduced_col_w; | ||||||||||||||||||||||||||||||||
| 647 | # if ( $width->{fract_calc}[$col] < 1 ) { | ||||||||||||||||||||||||||||||||
| 648 | # $width->{fract_calc}[$col] = "0 but true"; | ||||||||||||||||||||||||||||||||
| 649 | # # keep it true eaven if it is 0 for __cols_to_string to work properly. | ||||||||||||||||||||||||||||||||
| 650 | # } | ||||||||||||||||||||||||||||||||
| 651 | #} | ||||||||||||||||||||||||||||||||
| 652 | 0 | $width->{cols_calc}[$col] = $reduced_col_w; | |||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||
| 655 | 0 | my $prev_sum = $sum; | |||||||||||||||||||||||||||||||
| 656 | 0 | $sum = sum( @{$width->{cols_calc}} ); | |||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | if ( $sum == $prev_sum ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 658 | 0 | --$min_col_width; | |||||||||||||||||||||||||||||||
| 659 | 0 | ▶ | if ( $min_col_width < 2 ) { # never | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 660 | 0 | die "Value less than 1"; | |||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||
| 664 | 0 | my $remainder_w = $avail_w - $sum; | |||||||||||||||||||||||||||||||
| 665 | 0 | ▶ | if ( $remainder_w ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||
| 667 | 0 | REMAINDER_W: while ( 1 ) { | |||||||||||||||||||||||||||||||
| 668 | 0 | my $prev_remainder_w = $remainder_w; | |||||||||||||||||||||||||||||||
| 669 | 0 | for my $col ( @col_idx ) { | |||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | if ( $width->{cols_calc}[$col] < $width->{cols}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 671 | 0 | ++$width->{cols_calc}[$col]; | |||||||||||||||||||||||||||||||
| 672 | 0 | ▶ | if ( $width->{fract_calc}[$col] < $width->{fract}[$col] | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$width->{"fract_calc"}[$col] < $width->{"fract"}[$col] and $width->{"int"}[$col] + $width->{"fract_calc"}[$col] < $width->{"cols_calc"}[$col]
MC/DC0%0/2
$width->{"fract_calc"}[$col] < $width->{"fract"}[$col] and $width->{"int"}[$col] + $width->{"fract_calc"}[$col] < $width->{"cols_calc"}[$col]
$width->{"fract_calc"}[$col] < $width->{"fract"}[$col]
$width->{"int"}[$col] + $width->{"fract_calc"}[$col] < $width->{"cols_calc"}[$col]
Truth table0%0/3
A and B
A= $width->{"fract_calc"}[$col] < $width->{"fract"}[$col]B= $width->{"int"}[$col] + $width->{"fract_calc"}[$col] < $width->{"cols_calc"}[$col]
| |||||||||||||||||||||||||||||||||
| 673 | && $width->{int}[$col] + $width->{fract_calc}[$col] < $width->{cols_calc}[$col] ## | ||||||||||||||||||||||||||||||||
| 674 | ) { | ||||||||||||||||||||||||||||||||
| 675 | 0 | ++$width->{fract_calc}[$col] | |||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||
| 677 | 0 | --$remainder_w; | |||||||||||||||||||||||||||||||
| 678 | 0 | ▶ | if ( $remainder_w == 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 679 | 0 | last REMAINDER_W; | |||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | if ( $remainder_w == $prev_remainder_w ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 684 | 0 | last REMAINDER_W; | |||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||
| 689 | #else { | ||||||||||||||||||||||||||||||||
| 690 | # #$sum == $avail_w, nothing to do | ||||||||||||||||||||||||||||||||
| 691 | #} | ||||||||||||||||||||||||||||||||
| 692 | 0 | return; | |||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | sub __cols_to_string { | ||||||||||||||||||||||||||||||
|
Subroutine
__cols_to_string: not called CC=34 SCAR=70.8
| |||||||||||||||||||||||||||||||||
| 697 | 0 | my ( $self, $tbl_orig, $tbl_copy, $width, $progress ) = @_; | |||||||||||||||||||||||||||||||
| 698 | 0 | $progress->set_progress_bar(); | |||||||||||||||||||||||||||||||
| 699 | 0 | my $tab = ( ' ' x int( $width->{tab} / 2 ) ) . '|' . ( ' ' x int( $width->{tab} / 2 ) ); | |||||||||||||||||||||||||||||||
| 700 | 0 | my $one_precision_w = length sprintf "%.1e", 123; | |||||||||||||||||||||||||||||||
| 701 | 0 | my $ds = $self->{decimal_separator}; | |||||||||||||||||||||||||||||||
| 702 | 0 | my $regex_fract = "(\Q${ds}\E[0-9]+)\\z"; | |||||||||||||||||||||||||||||||
| 703 | 0 | my $lrb = ' ' x $width->{edge}; | |||||||||||||||||||||||||||||||
| 704 | 0 | my $header = $lrb; | |||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||
| 706 | 0 | HEADER: for my $col ( 0 .. $#{$width->{cols_calc}} ) { | |||||||||||||||||||||||||||||||
| 707 | 0 | $header .= adjust_to_printwidth( $tbl_copy->[0][$col], $width->{cols_calc}[$col] ); | |||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | if ( $self->{color} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 709 | 0 | my $orig_col = $self->{_used_cols_tbl_orig}[$col]; | |||||||||||||||||||||||||||||||
| 710 | 0 | ▶ | if ( defined $tbl_orig->[0][$orig_col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 711 | 0 | my @color = $tbl_orig->[0][$orig_col] =~ /(${\SGR_ES})/g; | |||||||||||||||||||||||||||||||
| 712 | 0 | ▶ | if ( @color ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 713 | 0 | $header =~ s/${\PH}/shift @color/ge; | |||||||||||||||||||||||||||||||
| 714 | 0 | $header .= "\e[0m"; | |||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | $header .= $col == $#{$width->{cols_calc}} ? $lrb : $tab; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||
| 720 | 0 | $tbl_copy->[0] = $header; # overwrite $tbl_copy to save memory | |||||||||||||||||||||||||||||||
| 721 | 0 | my $str; | |||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||
| 723 | 0 | ROW: for my $row ( 1 .. $#{$tbl_copy} ) { | |||||||||||||||||||||||||||||||
| 724 | 0 | $str = $lrb; | |||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||
| 726 | 0 | COL: for my $col ( 0 .. $#{$width->{cols_calc}} ) { | |||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | if ( ! length $tbl_copy->[$row][$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 728 | 0 | $str .= ' ' x $width->{cols_calc}[$col]; | |||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||
| 730 | elsif ( looks_like_number $tbl_copy->[$row][$col] ) { | ||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | if ( $width->{fract_calc}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | if ( $tbl_copy->[$row][$col] =~ /$regex_fract/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 733 | 0 | ▶ | if ( length $1 > $width->{fract_calc}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 734 | 0 | $tbl_copy->[$row][$col] = substr( $tbl_copy->[$row][$col], 0, -( length( $1 ) - $width->{fract_calc}[$col] ) ); | |||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||
| 736 | elsif ( length $1 < $width->{fract_calc}[$col] ) { | ||||||||||||||||||||||||||||||||
| 737 | 0 | $tbl_copy->[$row][$col] .= ' ' x ( $width->{fract_calc}[$col] - length $1 ); | |||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||
| 740 | elsif ( $tbl_copy->[$row][$col] !~ /[eE]/ ) { | ||||||||||||||||||||||||||||||||
| 741 | 0 | $tbl_copy->[$row][$col] .= ' ' x $width->{fract_calc}[$col]; | |||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||
| 743 | ▶ | elsif ( $tbl_copy->[$row][$col] =~ /[eE]-/ && $width->{fract}[$col] != $width->{fract_calc}[$col] ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$tbl_copy->[$row][$col] =~ /[eE]-/u and $width->{"fract"}[$col] != $width->{"fract_calc"}[$col]
MC/DC0%0/2
$tbl_copy->[$row][$col] =~ /[eE]-/u and $width->{"fract"}[$col] != $width->{"fract_calc"}[$col]
$tbl_copy->[$row][$col] =~ /[eE]-/u
$width->{"fract"}[$col] != $width->{"fract_calc"}[$col]
Truth table0%0/3
A and B
A= $tbl_copy->[$row][$col] =~ /[eE]-/uB= $width->{"fract"}[$col] != $width->{"fract_calc"}[$col]
| |||||||||||||||||||||||||||||||||
| 744 | 0 | $tbl_copy->[$row][$col] = sprintf "%.*f", $width->{fract_calc}[$col] - 1, $tbl_copy->[$row][$col]; | |||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||
| 747 | 0 | ▶ | if ( length $tbl_copy->[$row][$col] > $width->{cols_calc}[$col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | my $precision = $width->{cols_calc}[$col] - ( $one_precision_w + ( $tbl_copy->[$row][$col] < 0 ? 1 : 0 ) ) + 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 749 | # $one_precision_w + 1 if the number is signed (-) | ||||||||||||||||||||||||||||||||
| 750 | # $precision + 1 because $one_precision_w contains already one precision | ||||||||||||||||||||||||||||||||
| 751 | 0 | ▶ | if ( $precision == -1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 752 | 0 | $precision = 0; | |||||||||||||||||||||||||||||||
| 753 | # Difference between one-precision-width and zero-precision-width is 2 because zero precision has no dot. | ||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||
| 755 | 0 | ▶ | if ( $precision >= 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | while ( length( $tbl_copy->[$row][$col] = sprintf "%.*e", $precision, $tbl_copy->[$row][$col] ) > $width->{cols_calc}[$col] ) { ## | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 757 | 0 | --$precision; | |||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | last if $precision < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||
| 762 | 0 | ▶ | if ( $precision < 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 763 | 0 | $str .= ( '-' x $width->{cols_calc}[$col] ); | |||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||
| 765 | ▶ | elsif ( $precision == 0 && length $tbl_copy->[$row][$col] < $width->{cols_calc}[$col] ) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$precision == 0 and length $tbl_copy->[$row][$col] < $width->{"cols_calc"}[$col]
MC/DC0%0/2
$precision == 0 and length $tbl_copy->[$row][$col] < $width->{"cols_calc"}[$col]
$precision == 0
length $tbl_copy->[$row][$col] < $width->{"cols_calc"}[$col]
Truth table0%0/3
A and B
A= $precision == 0B= length $tbl_copy->[$row][$col] < $width->{"cols_calc"}[$col]
| |||||||||||||||||||||||||||||||||
| 766 | 0 | $str .= ' ' . $tbl_copy->[$row][$col]; | |||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||
| 768 | else { | ||||||||||||||||||||||||||||||||
| 769 | 0 | $str .= $tbl_copy->[$row][$col]; | |||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||
| 772 | elsif ( length $tbl_copy->[$row][$col] < $width->{cols_calc}[$col] ) { | ||||||||||||||||||||||||||||||||
| 773 | 0 | $str .= ' ' x ( $width->{cols_calc}[$col] - length $tbl_copy->[$row][$col] ) . $tbl_copy->[$row][$col]; | |||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||
| 775 | else { | ||||||||||||||||||||||||||||||||
| 776 | 0 | $str .= $tbl_copy->[$row][$col]; | |||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||
| 779 | else { | ||||||||||||||||||||||||||||||||
| 780 | 0 | $str .= adjust_to_printwidth( $tbl_copy->[$row][$col], $width->{cols_calc}[$col] ); | |||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||
| 782 | 0 | ▶ | if ( $self->{color} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 783 | 0 | my $orig_col = $self->{_used_cols_tbl_orig}[$col]; | |||||||||||||||||||||||||||||||
| 784 | 0 | ▶ | if ( defined $tbl_orig->[$row][$orig_col] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 785 | 0 | my @color = $tbl_orig->[$row][$orig_col] =~ /(${\SGR_ES})/g; | |||||||||||||||||||||||||||||||
| 786 | 0 | ▶ | if ( @color ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 787 | 0 | $str =~ s/${\PH}/shift @color/ge; | |||||||||||||||||||||||||||||||
| 788 | 0 | $str .= "\e[0m"; | |||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||
| 792 | 0 | ▶ | $str .= $col == $#{$width->{cols_calc}} ? $lrb : $tab; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||
| 794 | 0 | $tbl_copy->[$row] = $str; # overwrite $tbl_copy to save memory | |||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | if ( $progress->{show_progress_bar} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | if ( ++$progress->{count} > $progress->{next_update} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 797 | 0 | $progress->update_progress_bar(); | |||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||
| 801 | 0 | ▶ | if ( $progress->{show_progress_bar} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 802 | 0 | $progress->update_progress_bar(); | |||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||
| 804 | 0 | return $tbl_copy; # $tbl_copy is now $tbl_print | |||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||
| 808 | 0 | ▶ | sub __print_single_row { | ||||||||||||||||||||||||||||||
|
Subroutine
__print_single_row: not called CC=23 SCAR=63.1
| |||||||||||||||||||||||||||||||||
| 809 | 0 | my ( $self, $tbl_orig, $row, $width, $footer ) = @_; | |||||||||||||||||||||||||||||||
| 810 | 0 | my $avail_w = get_term_width() - 1; ## | |||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | if ( $self->{expanded_max_width} && $self->{expanded_max_width} < $avail_w ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"expanded_max_width"} and $self->{"expanded_max_width"} < $avail_w
MC/DC0%0/2
$self->{"expanded_max_width"} and $self->{"expanded_max_width"} < $avail_w
$self->{"expanded_max_width"}
$self->{"expanded_max_width"} < $avail_w
Truth table0%0/3
A and B
A= $self->{"expanded_max_width"}B= $self->{"expanded_max_width"} < $avail_w
| |||||||||||||||||||||||||||||||||
| 812 | 0 | $avail_w = $self->{expanded_max_width}; | |||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||
| 814 | 0 | my $max_key_w = max( @{$width->{col_names}} ) + 1; | |||||||||||||||||||||||||||||||
| 815 | 0 | ▶ | if ( $max_key_w > int( $avail_w / 3 ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 816 | 0 | $max_key_w = int( $avail_w / 3 ); | |||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||
| 818 | 0 | my $separator = ' : '; | |||||||||||||||||||||||||||||||
| 819 | 0 | my $sep_w = length( $separator ); | |||||||||||||||||||||||||||||||
| 820 | 0 | my $max_value_w = $avail_w - ( $max_key_w + $sep_w ); | |||||||||||||||||||||||||||||||
| 821 | 0 | my $separator_row = ' '; | |||||||||||||||||||||||||||||||
| 822 | 0 | my $row_data = [ ' Close with ENTER' ]; | |||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||
| 824 | 0 | for my $col ( @{$self->{_desired_cols_tbl_orig}} ) { | |||||||||||||||||||||||||||||||
| 825 | 0 | ▶ | if ( $self->{expanded_line_spacing} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 826 | 0 | push @$row_data, $separator_row; | |||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||
| 828 | 0 | ▶ | my $key = $tbl_orig->[0][$col] // $self->{undef}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$tbl_orig->[0][$col] // $self->{"undef"}
MC/DC0%0/2
$tbl_orig->[0][$col] // $self->{"undef"}
$tbl_orig->[0][$col]
$self->{"undef"}
Truth table0%0/3
A // B
A= $tbl_orig->[0][$col]B= $self->{"undef"}
| |||||||||||||||||||||||||||||||||
| 829 | 0 | my @key_color; | |||||||||||||||||||||||||||||||
| 830 | 0 | ▶ | if ( $self->{color} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 831 | 0 | $key =~ s/${\PH}//g; | |||||||||||||||||||||||||||||||
| 832 | 0 | ▶ | $key =~ s/(${\SGR_ES})/push( @key_color, $1 ) && ${\PH}/ge; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
push(@key_color, $1) && ${\"\x{feff}";}
MC/DC0%0/2
push(@key_color, $1) && ${\"\x{feff}";}
push(@key_color, $1)
${\"\x{feff}";}
Truth table0%0/3
A && B
A= push(@key_color, $1)B= ${\"\x{feff}";}
| |||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||
| 834 | 0 | ▶ | if ( $self->{binary_filter} && substr( $key, 0, 100 ) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$self->{"binary_filter"} and substr($key, 0, 100) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/u
MC/DC0%0/2
$self->{"binary_filter"} and substr($key, 0, 100) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/u
$self->{"binary_filter"}
substr($key, 0, 100) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/u
Truth table0%0/3
A and B
A= $self->{"binary_filter"}B= substr($key, 0, 100) =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F]/u
| |||||||||||||||||||||||||||||||||
| 835 | 0 | ▶ | if ( $self->{binary_filter} == 2 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 836 | 0 | ▶ | $key = sprintf( '%*v02X', ' ', $tbl_orig->[0][$col] // $self->{undef} ); | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$tbl_orig->[0][$col] // $self->{"undef"}
MC/DC0%0/2
$tbl_orig->[0][$col] // $self->{"undef"}
$tbl_orig->[0][$col]
$self->{"undef"}
Truth table0%0/3
A // B
A= $tbl_orig->[0][$col]B= $self->{"undef"}
| |||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||
| 838 | else { | ||||||||||||||||||||||||||||||||
| 839 | 0 | $key = $self->{binary_string}; | |||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||
| 841 | 0 | ▶ | if ( @key_color ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 842 | 0 | @key_color = (); | |||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||
| 845 | elsif ( $key =~ /[\p{Cc}\p{Noncharacter_Code_Point}\p{Cs}]/ ) { | ||||||||||||||||||||||||||||||||
| 846 | 0 | $key =~ s/\t/ /g; | |||||||||||||||||||||||||||||||
| 847 | 0 | $key =~ s/\v+/\ \ /g; | |||||||||||||||||||||||||||||||
| 848 | 0 | $key =~ s/[\p{Cc}\p{Noncharacter_Code_Point}\p{Cs}]//g; | |||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||
| 850 | 0 | my $key_w = print_columns( $key ); | |||||||||||||||||||||||||||||||
| 851 | 0 | ▶ | if ( $key_w > $max_key_w ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 852 | 0 | $key = cut_to_printwidth( $key, $max_key_w ); | |||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||
| 854 | elsif ( $key_w < $max_key_w ) { | ||||||||||||||||||||||||||||||||
| 855 | 0 | $key = ( ' ' x ( $max_key_w - $key_w ) ) . $key; | |||||||||||||||||||||||||||||||
| 856 | } | ||||||||||||||||||||||||||||||||
| 857 | 0 | ▶ | if ( @key_color ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 858 | 0 | $key =~ s/${\PH}/shift @key_color/ge; | |||||||||||||||||||||||||||||||
| 859 | 0 | $key .= "\e[0m"; | |||||||||||||||||||||||||||||||
| 860 | } | ||||||||||||||||||||||||||||||||
| 861 | 0 | ▶ | my $value = $tbl_orig->[$row][$col] // $self->{undef}; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$tbl_orig->[$row][$col] // $self->{"undef"}
MC/DC0%0/2
$tbl_orig->[$row][$col] // $self->{"undef"}
$tbl_orig->[$row][$col]
$self->{"undef"}
Truth table0%0/3
A // B
A= $tbl_orig->[$row][$col]B= $self->{"undef"}
| |||||||||||||||||||||||||||||||||
| 862 | # $value: color and invalid char handling in `line_fold` | ||||||||||||||||||||||||||||||||
| 863 | 0 | ▶ | if ( ref $value ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 864 | 0 | $value = _handle_reference( $value ); | |||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||
| 866 | 0 | my $subseq_tab = ' ' x ( $max_key_w + $sep_w ); | |||||||||||||||||||||||||||||||
| 867 | 0 | my $count; | |||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||
| 869 | 0 | for my $line ( line_fold( $value, { width => $max_value_w, color => $self->{color}, binary_filter => $self->{binary_filter}, join => 0 } ) ) { | |||||||||||||||||||||||||||||||
| 870 | 0 | ▶ | if ( ! $count++ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 871 | 0 | push @$row_data, $key . $separator . $line; | |||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||
| 873 | else { | ||||||||||||||||||||||||||||||||
| 874 | 0 | push @$row_data, $subseq_tab . $line; | |||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||||||
| 878 | 0 | my $regex; | |||||||||||||||||||||||||||||||
| 879 | 0 | ▶ | if ( $self->{expanded_line_spacing} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 880 | 0 | $regex = qr/^\Q$separator_row\E\z/; | |||||||||||||||||||||||||||||||
| 881 | } | ||||||||||||||||||||||||||||||||
| 882 | # Choose | ||||||||||||||||||||||||||||||||
| 883 | choose( | ||||||||||||||||||||||||||||||||
| 884 | $row_data, | ||||||||||||||||||||||||||||||||
| 885 | { prompt => '', layout => 2, clear_screen => 1, mouse => $self->{mouse}, hide_cursor => 0, empty => ' ', | ||||||||||||||||||||||||||||||||
| 886 | search => $self->{search}, skip_items => $regex, footer => $footer, page => $self->{page}, | ||||||||||||||||||||||||||||||||
| 887 | color => $self->{color}, codepage_mapping => $self->{codepage_mapping} } | ||||||||||||||||||||||||||||||||
| 888 | 0 | ); | |||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||
| 892 | 0 | ▶ | sub __search { | ||||||||||||||||||||||||||||||
|
Subroutine
__search: not called CC=11 SCAR=47.3
| |||||||||||||||||||||||||||||||||
| 893 | 0 | my ( $self, $tbl_orig ) = @_; | |||||||||||||||||||||||||||||||
| 894 | 0 | ▶ | if ( ! $self->{search} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 895 | 0 | return; | |||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||
| 897 | 0 | require Term::Form::ReadLine; | |||||||||||||||||||||||||||||||
| 898 | 0 | Term::Form::ReadLine->VERSION(0.544); | |||||||||||||||||||||||||||||||
| 899 | 0 | my $term = Term::Form::ReadLine->new(); | |||||||||||||||||||||||||||||||
| 900 | 0 | my $error_message; | |||||||||||||||||||||||||||||||
| 901 | 0 | my $prompt = "> \e[4msearch\e[0m: "; | |||||||||||||||||||||||||||||||
| 902 | 0 | my $default = ''; | |||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||
| 904 | 0 | READ: while ( 1 ) { | |||||||||||||||||||||||||||||||
| 905 | 0 | ▶ | my $string = $term->readline( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 906 | $prompt, | ||||||||||||||||||||||||||||||||
| 907 | { info => $error_message, hide_cursor => 2, clear_screen => defined $error_message ? 1 : 2, | ||||||||||||||||||||||||||||||||
| 908 | default => $default, color => 1 } | ||||||||||||||||||||||||||||||||
| 909 | ); | ||||||||||||||||||||||||||||||||
| 910 | 0 | ▶ | if ( ! length $string ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 911 | 0 | return; | |||||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||||
| 913 | 0 | print "\r${prompt}${string}"; | |||||||||||||||||||||||||||||||
| 914 | 0 | ▶ | if ( ! eval { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 915 | 0 | ▶ | $self->{_search_regex} = $self->{search} == 1 ? "(?i:$string)" : $string; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 916 | 0 | 'Teststring' =~ $self->{_search_regex}; | |||||||||||||||||||||||||||||||
| 917 | 0 | 1 | |||||||||||||||||||||||||||||||
| 918 | } ) { | ||||||||||||||||||||||||||||||||
| 919 | 0 | ▶ | $default = $default eq $string ? '' : $string; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 920 | 0 | $error_message = "$@"; | |||||||||||||||||||||||||||||||
| 921 | 0 | next READ; | |||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||
| 923 | 0 | last READ; | |||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||
| 925 | 1 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||
| 927 | # skip the header row | ||||||||||||||||||||||||||||||||
| 928 | 0 | for my $idx_row ( 1 .. $self->{_last_index} ) { | |||||||||||||||||||||||||||||||
| 929 | 0 | for ( @{$self->{_desired_cols_tbl_orig}} ) { | |||||||||||||||||||||||||||||||
| 930 | 0 | ▶ | if ( $tbl_orig->[$idx_row][$_] =~ /$self->{_search_regex}/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 931 | 0 | push @{$self->{_idx_search_matches}}, $idx_row; | |||||||||||||||||||||||||||||||
| 932 | 0 | last; | |||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||
| 936 | 0 | ▶ | if ( ! @{$self->{_idx_search_matches}} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 937 | 0 | my $message = '/' . $self->{_search_regex} . '/: No matches found.'; | |||||||||||||||||||||||||||||||
| 938 | # Choose | ||||||||||||||||||||||||||||||||
| 939 | 0 | choose( | |||||||||||||||||||||||||||||||
| 940 | [ 'Continue with ENTER' ], | ||||||||||||||||||||||||||||||||
| 941 | { prompt => $message, layout => 0, clear_screen => 1, hide_cursor => 0 } | ||||||||||||||||||||||||||||||||
| 942 | ); | ||||||||||||||||||||||||||||||||
| 943 | 0 | $self->{_search_regex} = ''; | |||||||||||||||||||||||||||||||
| 944 | 0 | return; | |||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||
| 946 | 0 | return; | |||||||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||
| 950 | 0 | ▶ | sub __reset_search { | ||||||||||||||||||||||||||||||
|
Subroutine
__reset_search: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 951 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 952 | 0 | $self->{_idx_search_matches} = []; | |||||||||||||||||||||||||||||||
| 953 | 0 | $self->{_search_regex} = ''; | |||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||
| 957 | 0 | ▶ | sub __header_sep { | ||||||||||||||||||||||||||||||
|
Subroutine
__header_sep: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 958 | 0 | my ( $self, $width ) = @_; | |||||||||||||||||||||||||||||||
| 959 | 0 | my $tab = ( '-' x int( $width->{tab} / 2 ) ) . '|' . ( '-' x int( $width->{tab} / 2 ) ); | |||||||||||||||||||||||||||||||
| 960 | 0 | my $lrb = '-' x $width->{edge}; | |||||||||||||||||||||||||||||||
| 961 | 0 | my $header_sep = $lrb; | |||||||||||||||||||||||||||||||
| 962 | 0 | for my $col ( 0 .. $#{$width->{cols_calc}} - 1 ) { | |||||||||||||||||||||||||||||||
| 963 | 0 | $header_sep .= '-' x $width->{cols_calc}[$col] . $tab; | |||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||
| 965 | 0 | $header_sep .= '-' x $width->{cols_calc}[$#{$width->{cols_calc}}] . $lrb; | |||||||||||||||||||||||||||||||
| 966 | 0 | return $header_sep; | |||||||||||||||||||||||||||||||
| 967 | } | ||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||
| 970 | 0 | ▶ | sub _handle_reference { | ||||||||||||||||||||||||||||||
|
Subroutine
_handle_reference: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 971 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||
| 972 | 0 | local $Data::Dumper::Useqq = 1; | |||||||||||||||||||||||||||||||
| 973 | 0 | local $Data::Dumper::Indent = 0; | |||||||||||||||||||||||||||||||
| 974 | 0 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||||||
| 975 | 0 | local $Data::Dumper::Maxdepth = 2; | |||||||||||||||||||||||||||||||
| 976 | 0 | return Data::Dumper::Dumper( $_[0] ); | |||||||||||||||||||||||||||||||
| 977 | } | ||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||
| 980 | 0 | ▶ | sub _minus_x_percent { | ||||||||||||||||||||||||||||||
|
Subroutine
_minus_x_percent: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 981 | #my ( $value, $percent ) = @_; | ||||||||||||||||||||||||||||||||
| 982 | 0 | ▶ | return int( $_[0] - ( $_[0] / 100 * $_[1] ) ) || 1; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
int $_[0] - $_[0] / 100 * $_[1] || 1
MC/DC0%0/1
int $_[0] - $_[0] / 100 * $_[1] || 1
int $_[0] - $_[0] / 100 * $_[1]
Truth table0%0/2
A
A= int $_[0] - $_[0] / 100 * $_[1]
| |||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||
| 987 | 1 | 1; | |||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||
| 989 | __END__ | ||||||||||||||||||||||||||||||||