line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::EX::Colormap; |
2
|
10
|
|
|
10
|
|
309464
|
use version; our $VERSION = version->declare("2.1.2"); |
|
10
|
|
|
|
|
9317
|
|
|
10
|
|
|
|
|
78
|
|
3
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
1106
|
use v5.14; |
|
10
|
|
|
|
|
59
|
|
5
|
10
|
|
|
10
|
|
663
|
use utf8; |
|
10
|
|
|
|
|
47
|
|
|
10
|
|
|
|
|
83
|
|
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
310
|
use Exporter 'import'; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
971
|
|
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
|
|
64
|
use Carp; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
730
|
|
15
|
10
|
|
|
10
|
|
3085
|
use Data::Dumper; |
|
10
|
|
|
|
|
29508
|
|
|
10
|
|
|
|
|
837
|
|
16
|
|
|
|
|
|
|
$Data::Dumper::Sortkeys = 1; |
17
|
|
|
|
|
|
|
|
18
|
10
|
|
|
10
|
|
72
|
use List::Util qw(min max first); |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
1030
|
|
19
|
|
|
|
|
|
|
|
20
|
10
|
|
|
10
|
|
4576
|
use parent 'Getopt::EX::LabeledParam'; |
|
10
|
|
|
|
|
2922
|
|
|
10
|
|
|
|
|
60
|
|
21
|
10
|
|
|
10
|
|
4678
|
use Getopt::EX::Util; |
|
10
|
|
|
|
|
32
|
|
|
10
|
|
|
|
|
472
|
|
22
|
10
|
|
|
10
|
|
76
|
use Getopt::EX::Func qw(callable); |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
432
|
|
23
|
|
|
|
|
|
|
|
24
|
10
|
|
|
10
|
|
5808
|
use Term::ANSIColor::Concise qw(:all); |
|
10
|
|
|
|
|
49696
|
|
|
10
|
|
|
|
|
1824
|
|
25
|
|
|
|
|
|
|
{ |
26
|
10
|
|
|
10
|
|
76
|
no strict 'refs'; |
|
10
|
|
|
|
|
85
|
|
|
10
|
|
|
|
|
9602
|
|
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
|
|
2217
|
my $sub = our $AUTOLOAD =~ s/.*:://r; |
45
|
2
|
50
|
|
|
|
273
|
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
|
199
|
my $class = shift; |
64
|
2
|
|
|
|
|
20
|
my $obj = $class->SUPER::new; |
65
|
2
|
|
|
|
|
11
|
my %opt = @_; |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
12
|
$obj->{CACHE} = {}; |
68
|
2
|
|
50
|
|
|
17
|
$opt{CONCAT} //= "^"; # Reset character for LabeledParam object |
69
|
2
|
|
|
|
|
16
|
$obj->configure(%opt); |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
7
|
$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
|
33
|
my $obj = shift; |
88
|
5
|
|
|
|
|
8
|
my $color = shift; |
89
|
5
|
|
|
|
|
6
|
my $text = shift; |
90
|
|
|
|
|
|
|
|
91
|
5
|
|
|
|
|
9
|
my $map = $obj->{HASH}; |
92
|
5
|
50
|
|
|
|
12
|
my $c = exists $map->{$color} ? $map->{$color} : $color; |
93
|
|
|
|
|
|
|
|
94
|
5
|
50
|
|
|
|
11
|
return $text unless $c; |
95
|
|
|
|
|
|
|
|
96
|
5
|
|
|
|
|
16
|
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__ |