line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::EX::Colormap; |
2
|
10
|
|
|
10
|
|
294146
|
use version; our $VERSION = version->declare("2.1.4"); |
|
10
|
|
|
|
|
8150
|
|
|
10
|
|
|
|
|
54
|
|
3
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
988
|
use v5.14; |
|
10
|
|
|
|
|
50
|
|
5
|
10
|
|
|
10
|
|
632
|
use utf8; |
|
10
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
65
|
|
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
293
|
use Exporter 'import'; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
878
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
9
|
|
|
|
|
|
|
qw( colorize colorize24 ansi_code ansi_pair csi_code ), |
10
|
|
|
|
|
|
|
qw( colortable colortable6 colortable12 colortable24 ), |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); |
13
|
|
|
|
|
|
|
|
14
|
10
|
|
|
10
|
|
67
|
use Carp; |
|
10
|
|
|
|
|
28
|
|
|
10
|
|
|
|
|
748
|
|
15
|
10
|
|
|
10
|
|
2667
|
use Data::Dumper; |
|
10
|
|
|
|
|
28989
|
|
|
10
|
|
|
|
|
756
|
|
16
|
|
|
|
|
|
|
$Data::Dumper::Sortkeys = 1; |
17
|
|
|
|
|
|
|
|
18
|
10
|
|
|
10
|
|
75
|
use List::Util qw(min max first); |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
981
|
|
19
|
|
|
|
|
|
|
|
20
|
10
|
|
|
10
|
|
4565
|
use parent 'Getopt::EX::LabeledParam'; |
|
10
|
|
|
|
|
2767
|
|
|
10
|
|
|
|
|
55
|
|
21
|
10
|
|
|
10
|
|
4626
|
use Getopt::EX::Util; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
455
|
|
22
|
10
|
|
|
10
|
|
68
|
use Getopt::EX::Func qw(callable); |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
417
|
|
23
|
|
|
|
|
|
|
|
24
|
10
|
|
|
10
|
|
6000
|
use Term::ANSIColor::Concise qw(:all); |
|
10
|
|
|
|
|
52655
|
|
|
10
|
|
|
|
|
1857
|
|
25
|
|
|
|
|
|
|
{ |
26
|
10
|
|
|
10
|
|
79
|
no strict 'refs'; |
|
10
|
|
|
|
|
75
|
|
|
10
|
|
|
|
|
9009
|
|
27
|
|
|
|
|
|
|
*colorize = \&ansi_color; |
28
|
|
|
|
|
|
|
*colorize24 = \&ansi_color_24; |
29
|
|
|
|
|
|
|
for my $name ( |
30
|
|
|
|
|
|
|
qw( NO_NO_COLOR |
31
|
|
|
|
|
|
|
NO_COLOR |
32
|
|
|
|
|
|
|
RGB24 |
33
|
|
|
|
|
|
|
LINEAR_256 |
34
|
|
|
|
|
|
|
LINEAR_GRAY |
35
|
|
|
|
|
|
|
NO_RESET_EL |
36
|
|
|
|
|
|
|
SPLIT_ANSI |
37
|
|
|
|
|
|
|
)) { |
38
|
|
|
|
|
|
|
*{$name} = *{"Term::ANSIColor::Concise::$name"}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#use Term::ANSIColor::Concise::Table qw(:all); |
43
|
|
|
|
|
|
|
sub AUTOLOAD { |
44
|
2
|
|
|
2
|
|
2009
|
my $sub = our $AUTOLOAD =~ s/.*:://r; |
45
|
2
|
50
|
|
|
|
284
|
return if $sub eq 'DESTROY'; |
46
|
0
|
0
|
|
|
|
0
|
if ($sub =~ /^colortable(?:|6|12|24)$/) { |
47
|
|
|
|
|
|
|
require Term::ANSIColor::Concise::Table |
48
|
0
|
0
|
|
|
|
0
|
and Term::ANSIColor::Concise::Table->import(':all'); |
49
|
0
|
|
|
|
|
0
|
goto &$sub; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
0
|
die "Invalid call for $sub().\n"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
our $NO_NO_COLOR //= $ENV{GETOPTEX_NO_NO_COLOR}; |
55
|
|
|
|
|
|
|
our $NO_COLOR //= !$NO_NO_COLOR && defined $ENV{NO_COLOR}; |
56
|
|
|
|
|
|
|
our $RGB24 //= $ENV{COLORTERM}//'' eq 'truecolor' || $ENV{GETOPTEX_RGB24}; |
57
|
|
|
|
|
|
|
our $LINEAR_256 //= $ENV{GETOPTEX_LINEAR_256}; |
58
|
|
|
|
|
|
|
our $LINEAR_GRAY //= $ENV{GETOPTEX_LINEAR_GRAY}; |
59
|
|
|
|
|
|
|
our $NO_RESET_EL //= $ENV{GETOPTEX_NO_RESET_EL}; |
60
|
|
|
|
|
|
|
our $SPLIT_ANSI //= $ENV{GETOPTEX_SPLIT_ANSI}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new { |
63
|
2
|
|
|
2
|
1
|
216
|
my $class = shift; |
64
|
2
|
|
|
|
|
21
|
my $obj = $class->SUPER::new; |
65
|
2
|
|
|
|
|
13
|
my %opt = @_; |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
14
|
$obj->{CACHE} = {}; |
68
|
2
|
|
50
|
|
|
15
|
$opt{CONCAT} //= "^"; # Reset character for LabeledParam object |
69
|
2
|
|
|
|
|
18
|
$obj->configure(%opt); |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
9
|
$obj; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub index_color { |
75
|
0
|
|
|
0
|
1
|
0
|
my $obj = shift; |
76
|
0
|
|
|
|
|
0
|
my $index = shift; |
77
|
0
|
|
|
|
|
0
|
my $text = shift; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
my $list = $obj->{LIST}; |
80
|
0
|
0
|
|
|
|
0
|
if (@$list) { |
81
|
0
|
|
|
|
|
0
|
$text = $obj->color($list->[$index % @$list], $text, $index); |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
0
|
$text; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub color { |
87
|
5
|
|
|
5
|
1
|
28
|
my $obj = shift; |
88
|
5
|
|
|
|
|
8
|
my $color = shift; |
89
|
5
|
|
|
|
|
7
|
my $text = shift; |
90
|
|
|
|
|
|
|
|
91
|
5
|
|
|
|
|
8
|
my $map = $obj->{HASH}; |
92
|
5
|
50
|
|
|
|
13
|
my $c = exists $map->{$color} ? $map->{$color} : $color; |
93
|
|
|
|
|
|
|
|
94
|
5
|
50
|
|
|
|
12
|
return $text unless $c; |
95
|
|
|
|
|
|
|
|
96
|
5
|
|
|
|
|
19
|
cached_ansi_color($obj->{CACHE}, $c, $text); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub colormap { |
100
|
0
|
|
|
0
|
1
|
|
my $obj = shift; |
101
|
0
|
|
|
|
|
|
my %opt = @_; |
102
|
0
|
|
0
|
|
|
|
$opt{name} //= "--newopt"; |
103
|
0
|
|
0
|
|
|
|
$opt{option} //= "--colormap"; |
104
|
0
|
|
0
|
|
|
|
$opt{sort} //= "length"; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $hash = $obj->{HASH}; |
107
|
|
|
|
|
|
|
join "\n", ( |
108
|
|
|
|
|
|
|
"option $opt{name} \\", |
109
|
0
|
|
|
|
|
|
do { |
110
|
0
|
0
|
|
|
|
|
my $maxlen = $opt{noalign} ? "" : do { |
111
|
0
|
|
|
|
|
|
max map { length } keys %{$hash}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
}; |
113
|
0
|
|
|
|
|
|
my $format = "\t%s %${maxlen}s=%s \\"; |
114
|
0
|
|
|
|
|
|
my $compare = do { |
115
|
0
|
0
|
|
|
|
|
if ($opt{sort} eq "length") { |
116
|
0
|
0
|
|
0
|
|
|
sub { length $a <=> length $b or $a cmp $b }; |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} else { |
118
|
0
|
|
|
0
|
|
|
sub { $a cmp $b }; |
|
0
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
map { |
122
|
0
|
|
0
|
|
|
|
sprintf $format, $opt{option}, $_, $hash->{$_} // ""; |
123
|
0
|
|
|
|
|
|
} sort $compare keys %{$hash}; |
|
0
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
}, |
125
|
|
|
|
|
|
|
"\t\$\n", |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |