| 1 | |||||||||||||||||||||||||||||
| 2 | package App::HI; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Text::Table; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Term::Size; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '2.7191_2'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub top_matter { | ||||||||||||||||||||||||||||
| 11 | 3 | ▶ | my $no_extra = shift; | ||||||||||||||||||||||||||
|
Subroutine
top_matter: called CC=5 SCAR=17.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 3 | my @to_import = qw(color colored colorvalid); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | if( $no_extra ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | eval qq/ use Term::ANSIColor qw(@to_import); 1 / | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | or die $@; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | } else { | ||||||||||||||||||||||||||||
| 19 | 3 | ▶ | eval qq/ use Term::ANSIColorx::ColorNicknames qw(@to_import); 1 / | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | or die $@; | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | eval q { use Term::ANSIColorx::AutoFilterFH qw(filtered_handle); 1 } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | or die $@; | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub fire_filter { | ||||||||||||||||||||||||||||
| 28 | 3 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
fire_filter: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 3 | my %o = @_; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | top_matter( $o{nixnics} ); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | my $newstdout = filtered_handle(\*STDOUT, @ARGV); | |||||||||||||||||||||||||||
| 34 | 3 | $| = 1; my $oldstdout = select $newstdout; $|=1; | |||||||||||||||||||||||||||
| 35 | 3 | ▶ | $newstdout->set_truncate($o{trunc}) if $o{trunc}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 3 | binmode $newstdout, ':utf8'; | |||||||||||||||||||||||||||
| 38 | 3 | binmode STDIN, ':utf8'; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | ▶ | while(<STDIN>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 7 | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub sort_colors { | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my %yet_seen; | ||||||||||||||||||||||||||
|
Subroutine
sort_colors: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | map {$_->{cn}} | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sort { | ||||||||||||||||||||||||||||
| 51 | $a->{bg} <=> $b->{bg} || | ||||||||||||||||||||||||||||
| 52 | $a->{at} <=> $b->{at} || | ||||||||||||||||||||||||||||
| 53 | $a->{fg} <=> $b->{fg} | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$App::HI::a->{"bg"} <=> $App::HI::b->{"bg"} or $App::HI::a->{"at"} <=> $App::HI::b->{"at"}
MC/DC0%0/2
$App::HI::a->{"bg"} <=> $App::HI::b->{"bg"} or $App::HI::a->{"at"} <=> $App::HI::b->{"at"}
$App::HI::a->{"bg"} <=> $App::HI::b->{"bg"}
$App::HI::a->{"at"} <=> $App::HI::b->{"at"}
Truth table0%0/3
A or B
A= $App::HI::a->{"bg"} <=> $App::HI::b->{"bg"}B= $App::HI::a->{"at"} <=> $App::HI::b->{"at"}
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | map { | ||||||||||||||||||||||||||||
| 57 | 0 | my $res = { cn => $_ }; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | my @v = map { $_ >= 90 && $_ <= 107 ? $_-60 : $_ } ( color($_) =~ m/(\d+)/g ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ >= 90 and $_ <= 107
MC/DC0%0/2
$_ >= 90 and $_ <= 107
$_ >= 90
$_ <= 107
Truth table0%0/3
A and B
A= $_ >= 90B= $_ <= 107
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | $res->{at} = grep {$_ <= 8} @v; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | $res->{fg} = grep {$_ >= 30 && $_ <= 37} @v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $res->{bg} = grep {$_ >= 40 && $_ <= 47} @v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $res->{at} = 0 unless $res->{at}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $res->{fg} = 30 unless $res->{fg}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $res->{bg} = 40 unless $res->{bg}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | $res; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | grep { | ||||||||||||||||||||||||||||
| 72 | 0 | my $valid = colorvalid($_); | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | warn "$_ isn't valid" unless $valid; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | $valid | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | grep { | ||||||||||||||||||||||||||||
| 79 | 0 | !$yet_seen{$_}++ | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | @_ | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub list_colors { | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
list_colors: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 0 | my %o = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | top_matter( $o{nixnics} => qw(color colorvalid) ); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $table; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | my @colors = sort_colors( | |||||||||||||||||||||||||||
| 94 | map("bold $_", qw( black red green yellow blue magenta cyan white )), | ||||||||||||||||||||||||||||
| 95 | qw( black red green yellow blue magenta cyan white ), | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | "white on_black", "white on_red", "blue on_green", "black on_yellow", | ||||||||||||||||||||||||||||
| 98 | "white on_blue", "white on_magenta", "black on_cyan", "black on_white", | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | "pitch on white", | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | keys %Term::ANSIColorx::ColorNicknames::NICKNAMES, | ||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | my ($columns, $rows) = Term::Size::chars *STDOUT; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | $columns --; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | my $m = 20; | |||||||||||||||||||||||||||
| 110 | UGH_SO_BAD: { | ||||||||||||||||||||||||||||
| 111 | # XXX: this is so in-efficient it makes my soul hurt | ||||||||||||||||||||||||||||
| 112 | 0 | $table = Text::Table->new; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | my @row; | |||||||||||||||||||||||||||
| 115 | 0 | for(@colors) { | |||||||||||||||||||||||||||
| 116 | 0 | push @row, $_; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | unless( @row % $m ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $table->add(map {$_ ? colored($_, $_) : $_} @row); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | @row = (); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $table->add(map {$_ ? colored($_, $_) : $_} @row); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | $m -= 2; | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | redo UGH_SO_BAD if $table->width > $columns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | print $table; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||